declare @x varchar(100),@string varchar(800)
set @x="('1389','0736')"set @string="select pub_name from publishers where pub_id in "+@x exec(@string)
set @x="('1389','0736')"set @string="select pub_name from publishers where pub_id in "+@x exec(@string)
比如说:
Set @string = @string + 'select * into #temptable ...'
exec(@string)
如果在直接写select * from #temptable是不行的,因为不再同一进程。
所以只能挤在@string内.
FROM publishers
WHERE pub_id in (select pub_id from temp)
temp中放你的查询信息
declare @x varchar(100)SET @x = '''1389'', ''0736'''select @x as test into #tempSELECT pub_name
FROM publishers
WHERE pub_id in (select test from #temp)
select '1389' as test into #temp
insert into #temp(test) values('0736')SELECT pub_name
FROM publishers
WHERE pub_id in (select test from #temp)
test
1389
0736
再存储过程中写
set @x = @x+'select * from table where 条件 in ('''+参数+''')'
...所以@x受到8000限制
如果不写@x这样,
在存储过程中头上我就要再replace(参数,''''',''''',''',''')
这样我又回到了我最初提出的问题..
如果按蓝天的方法我就需要拆卸大字串再存入临时表,也许要做2000个insert
还有如何在存储过程中拆这个字串,开销如何?
在存储过程中拆这个字串
---------------------方法很簡單,開銷很小!請看:http://www.csdn.net/expert/topic/508/508081.xml
中的第二題。
FROM publishers
WHERE pub_id = '1389'
union
SELECT pub_name
FROM publishers
WHERE pub_id = '0736'或者是 SELECT pub_name
FROM publishers
WHERE (pub_id = '0736' or pub_id ='1386')
FROM publishers
WHERE pub_id = '1389'
union
SELECT pub_name
FROM publishers
WHERE pub_id = '0736'或者是 SELECT pub_name
FROM publishers
WHERE (pub_id = '0736' or pub_id ='1386')