真是給我想破頭
原始的情形是很容易解決的,
ex:
--************************************************
declare @a varchar(200)
set @a='''a'',''b'''
declare @Statement varchar(4000)
set @Statement ='select * from tableA where tableA.column1 in ('+@a+')'
exec (@Statement)
--************************************************
就可以簡單解決
但...
一遇到Reporting Services就破功了
因為用exec執行query, Reporting Services是無法抓到column的
解決方法有很多種,不過很多都很複雜
所以
使用自製的split function應該是最簡單的方式吧!
--************************************************
create function f_split(@c varchar(2000),@split varchar(2))
returns @t table(col varchar(20))
as
begin
while(charindex(@split,@c)0)
begin
insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))
set @c = stuff(@c,1,charindex(@split,@c),'')
end
insert @t(col) values (@c)
return
end
--************************************************
--執行結果
select * from dbo.f_split('dfkd,dfdkdf,dfdkf,dffjk',',')
drop function f_split
col
--------------------
dfkd
dfdkdf
dfdkf
dffjk
(所影响的行数为 4 行)
--************************************************
資料來源:http://space.flash8.net/space/?18713/action_viewspace_itemid_343495.html
只要將in子句後加入select敘述
ex: in (select * from dbo.f_split(要斷的字串,'分隔符號'))
就可以抓到囉!
---
結論是...
Reporting Services真是鳥!!
- Dec 30 Tue 2008 12:45
Reporting Services若遇到要用in子句時,該如何接收參數?
close
全站熱搜
留言列表