declare @qry as varchar(max)
declare @db as varchar(25)
declare @item as varchar(25)
declare @U_Parentcode as varchar(25)
set @U_Parentcode ='CDM51306520'
set @db ='Marda_Test'
set @qry ='select @item =itemcode from ' + @db + '.[dbo].[OITM] where ItemCode=''' + @U_Parentcode +''''
execute (@qry)
print @item
收到类似“必须声明标量变量“@item”之类的错误。