关于SQL的拼接,单引号问题~~在线等~~着急~~
declare @Sql varchar(1000)declare @ACCOUNT varchar(50)='-1' --@ACCOUNT 为 testName 时也需要符合Set @Sql ='select * from T_ORDER where ('+CASE @ACCOUNT WHEN '-1' THEN '1=1' ELSE 'ACCOUNT = '''+CAST(@ACCOUNT AS varchar(50)) END+''') 'select @Sql
ACCOUNT = '''+CAST(@ACCOUNT AS varchar(50)) END+'''
ACCOUNT = '+CAST(@ACCOUNT AS varchar(50)) END+'
declare @Sql varchar(1000)declare @ACCOUNT varchar(50)='-1' --@ACCOUNT 为 testName 时也需要符合Set @Sql ='select * from T_ORDER where ('+CASE @ACCOUNT WHEN '-1' THEN '''' ELSE 'ACCOUNT = '''+CAST(@ACCOUNT AS varchar(50)) END+''') 'select @Sql
[解决办法]
declare @Sql varchar(1000)declare @ACCOUNT varchar(50) --@ACCOUNT 为 testName 时也需要符合set @ACCOUNT='-1'Set @Sql ='select * from T_ORDER where ('+CASE @ACCOUNT WHEN '-1' THEN '1=1' ELSE 'ACCOUNT = ''' +CAST(@ACCOUNT AS varchar(50)) END+') 'select @Sql
[解决办法]
declare @Sql varchar(1000)
declare @ACCOUNT varchar(50)='-1' --@ACCOUNT 为 testName 时也需要符合
Set @Sql ='select * from T_ORDER where ('+CASE @ACCOUNT WHEN '-1' THEN ' 1=1 ' ELSE ' ACCOUNT = '''+CAST(@ACCOUNT AS varchar(50))+'''' END +')'
select @Sql