declare @sql varchar(8000)
set @mth='('+ @mth +')'
set @dep='('+ @dep +')'
set @sql='
select mth,compid,depname,sum(mtotal) as total from call_list
where Mth in' + @mth + 'and depname in (' + @dep + ')
group by mth,compid,depname'
我这里的@mth 和 @dep 都是字符串来的,这样查出来的sql语句变量里面是没有引号的
要怎么把这个引号加上啊?
set @sql='
select mth,compid,depname,sum(mtotal) as total from call_list
where Mth in''' + @mth + '''and depname in (''' + @dep + ''')
group by mth,compid,depname'
declare @sql varchar(8000)
set @mth='('+ @mth +')'
set @dep='('+ @dep +')'
set @sql='
select mth,compid,depname,sum(mtotal) as total from call_list
where Mth in ''' + @mth + ''' and depname in (''' + @dep + ''')
group by mth,compid,depname'
set @dep='('+ replace(@dep,'''','''''') +')'
set @mth='1,2,3'
set @dep='4,5,6' --不要加括号了
set @sql='
select mth,compid,depname,sum(mtotal) as total from call_list
where Mth in (' + @mth + ') and depname in (' + @dep + ')
group by mth,compid,depname'