声明多个变量字符串以在IN语句中使用('i','j')

时间:2015-07-30 14:36:10

标签: sql sql-server sql-server-2008-r2

我正在尝试连接一个字符串,以便我可以在in语句中使用它。我收到了一个错误:

  

“'='附近的语法不正确。”

我正在做什么?

DECLARE @Year uniqueidentifier = (SELECT TOP 1 y.des_zyearId FROM des_zyearset y WHERE y.des_YearText  = 2015)

--this is where I'm trying to concatenate

declare @heat varchar(70) = ('''' + (select top 1 fu.des_zfuelusagetypeId from des_zfuelusagetypeSet fu where = 'heat') + ', ' + (select top 1 fu.des_zfuelusagetypeId from des_zfuelusagetypeSet fu where = 'both') + '''')

1 个答案:

答案 0 :(得分:0)

declare @heat varchar(70) = 
('''' + (select top 1 fu.des_zfuelusagetypeId from des_zfuelusagetypeSet fu   
 where = 'heat' --->error here
)
 + ', ' + (select top 1 fu.des_zfuelusagetypeId from 
 des_zfuelusagetypeSet fu 
where = 'both'   --->error here
 ) + '''')

select语句中存在错误。您说的是where = 'heat',它应该是where fu.somecolumn = 'heat'。同样,将其更改为第二个select