日期:2014-05-18  浏览次数:20495 次

char 列名 无效
declare   @letter   char(1)
declare   @sql   varchar(299)

set   @letter= 'a '

set   @sql= 'select   *   from   syinfo_subzone '
set   @sql=@sql+ '   where   sz_letter   =cast(@letter   as   char(1)) '
exec   (@sql)

服务器:   消息   207,级别   16,状态   3,行   1
列名   'a '   无效。

------解决方案--------------------
declare @letter char(1)
declare @sql varchar(299)

set @letter= 'a '

set @sql= 'select * from syinfo_subzone '
set @sql=@sql+ ' where sz_letter = ' ' ' +cast(@letter as char(1)) + ' ' ' '
exec (@sql)
------解决方案--------------------
--try

declare @letter char(1)
declare @sql varchar(299)

set @letter= 'a '

set @sql= 'select * from syinfo_subzone '
set @sql=@sql+ ' where sz_letter =cast( '+@letter+ ' as char(1)) '
exec (@sql)
------解决方案--------------------
--试试
declare @sql varchar(299)
set @sql= 'declare @letter char(1) set @letter= ' 'a ' ' select * from syinfo_subzone where sz_letter =cast(@letter as char(1)) '
exec (@sql)


------解决方案--------------------
这样看看:
declare @letter char(1)
declare @sql varchar(299)

set @letter= 'a '

set @sql= 'select * from syinfo_subzone '
set @sql=@sql+ ' where sz_letter = '+@letter
exec (@sql)