日期:2014-05-18 浏览次数:20548 次
drop PROCEDURE [Proc_test] GO create PROCEDURE [Proc_test] @name varchar(20) AS BEGIN select * from tb1 where name in(@name) END GO
create PROCEDURE [Proc_test] @name varchar(20) AS BEGIN exec('select * from tb1 where name in('+@name+')') END GO
------解决方案--------------------
select * from tb1 where charindex(','+name+',' , ','+@name+',') > 0
------解决方案--------------------
drop PROCEDURE [Proc_test] GO create PROCEDURE [Proc_test] @name varchar(20) AS BEGIN exec('select * from tb1 where name in('+@name+')') END GO
------解决方案--------------------
drop PROCEDURE [Proc_test] GO create PROCEDURE [Proc_test] @name varchar(20) AS BEGIN declare @sql nvarchar(1000) set @sql='select * from tb1 where name in('+@name+')' exec(@sql) END GO exec PROC_test '''Z001'',''Z002'''
------解决方案--------------------
drop PROCEDURE [Proc_test]
GO
create PROCEDURE [Proc_test]
@name varchar(20)
AS
BEGIN
select * from tb1 where charindex(','+name+',' , ','+@name+',') > 0
END
GO
exec PROC_test 'Z001,Z002'
------解决方案--------------------
给lz提个醒。。
在MSSQL中。单引号可以用作转移字符。。
比如:
print ''''
输出'
------解决方案--------------------
动态sql,效率比较差吧
------解决方案--------------------
动态SQL 不错的选择