读书人

sql server 存储过程里的字符单引号如

发布时间: 2012-04-13 13:50:24 作者: rapoo

sql server 存储过程里的字符单引号怎么写?

SQL code
alter procedure [dbo].[plp_elpoot001_ok]( @tlpsofc01 nvarchar(20))asdeclare @sql nvarchar(1000)declare @tsyitmp nvarchar(50) begin set @tsyitmp=(select tlpsofc11 from tlpsofc where tlpsofc01=@tlpsofc01) set @sql='update a set a.' set @sql=@sql+@tsyitmp set @sql=@sql+' =b.tlpsofd06 from tsyi a,tlpsofd b where b.tlpsofd02=a.tsyi01 and a.tsyi01 in(select tlpsofd02 from tlpsofd where tlpsofd01= ' set @sql=@sql+ @tlpsofc01 +')'exec( @sql)end调试后得到的sql是:update a set a.tsyi40 =b.tlpsofd06 from tsyi a,tlpsofd b where b.tlpsofd02=a.tsyi01 and a.tsyi01 in(select tlpsofd02 from tlpsofd where tlpsofd01=CCG20120408001 )我想得到:update a set a.tsyi40 =b.tlpsofd06 from tsyi a,tlpsofd b where b.tlpsofd02=a.tsyi01 and a.tsyi01 in(select tlpsofd02 from tlpsofd where tlpsofd01='CCG20120408001' )也就是最后那个where参数要加上引号.


[解决办法]
SQL code
declare @tlpsofc01 varchar(20)set @tlpsofc01='CCG20120408001'select 'select * from tablename where tlpsofc01='+@tlpsofc01/*select * from tablename where tlpsofc01=CCG20120408001*/select 'select * from tablename where tlpsofc01='+''''+@tlpsofc01+''''/*select * from tablename where tlpsofc01='CCG20120408001'*/
[解决办法]
SQL code
set @sql='update a set a.' set @sql=@sql+@tsyitmp set @sql=@sql+' =b.tlpsofd06 from tsyi a,tlpsofd b where b.tlpsofd02=a.tsyi01 and a.tsyi01 in(select tlpsofd02 from tlpsofd where tlpsofd01= ''' set @sql=@sql+ @tlpsofc01 +''')' 

读书人网 >SQL Server

热点推荐