当前位置: 代码迷 >> Sql Server >> sql server 存储过程里的字符单引号如何写
  详细解决方案

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

热度:8   发布时间:2016-04-27 13:30:21.0
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 [email protected]) set @sql='update a set a.' set @[email protected][email protected] set @[email protected]+' =b.tlpsofd06 from tsyi a,tlpsofd b where b.tlpsofd02=a.tsyi01 and a.tsyi01 in(select tlpsofd02 from tlpsofd where tlpsofd01= ' set @[email protected]+ @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 [email protected]/*select * from tablename where tlpsofc01=CCG20120408001*/select 'select * from tablename where [email protected]+''''/*select * from tablename where tlpsofc01='CCG20120408001'*/
------解决方案--------------------
SQL code
set @sql='update a set a.' set @[email protected][email protected] set @[email protected]+' =b.tlpsofd06 from tsyi a,tlpsofd b where b.tlpsofd02=a.tsyi01 and a.tsyi01 in(select tlpsofd02 from tlpsofd where tlpsofd01= ''' set @[email protected]+ @tlpsofc01 +''')'
  相关解决方案