0

I've made a stored procedure and got the error message below, dont know why. I've been looking around for some answers and with some other guys here at the office but they're all unsure of the problem. Hoping someone here has had the same problem and knows the solution to this.

Msg 116, Level 16, State 1, Procedure Name_Stored_Procedure, 
Line 113 Only one expression can be specified in the select list 
when the subquery is not introduced with EXISTS.

Here is my Code

 Set @SQLstring = 
 'Update #TempTable set Col1' + case when len(Convert(Varchar, (4+@counter)))=1 
 then '0' else '' end 
 + Convert(Varchar,(4+@counter)) + '=''' + 
 (select @Year, @Month, 
 Convert(Varchar,count(distinct Table.Column1)) 
 from Databse.Table 
 where DATEPART(yy,Time) = @Year 
 and DATEPART(mm,Time) = @Month 
 and Table.Column2 = @Column2 and Column3 in ('X','Z','Y - A')) 
 +''' where row = ' + CONVERT(varchar,10+@somevariable * 12)
 exec('' + @SQLstring +'')
4

3 に答える 3

2

SQL の文字列を作成して動的 SQL で実行する場合は、それを文字列として扱う必要があります。

 Set @SQLstring = 
     'Update #TempTable set Col' 
            + case when len(Convert(Varchar, (4+@counter)))=1 then '0' else '' end
     ...

内部選択で@year, @month、結果からを削除します

 + ( select Convert(Varchar,count(distinct Table.Column1)) from databse.Table....
于 2013-10-15T12:43:36.803 に答える
0

CONCAT(@年、@月、変換....)を選択

于 2013-10-15T13:11:13.410 に答える