在sql server中显示带有表列(select语句)的变量

时间:2013-08-13 09:15:35

标签: sql sql-server variables stored-procedures

这里我想要显示带表格列的变量值

declare @BaseMetal varchar(40)
set @BaseMetal='18K'

 SELECT   CAST(@BaseMetal as varchar(40)) 'BaseMetal', tbl.Columm1,tbl.Columm2, tbl.Columm3 from tbl

O / P应该是:

BaseMetal   Columm1   Columm2     Columm3 
  18K       colval1    colval1    colval1
  18K       colval2    colval2    colval2

但是当我尝试它时显​​示错误Must declare the scalar variable "@BaseMetal".

1 个答案:

答案 0 :(得分:0)

你不需要演员。

declare @BaseMetal varchar(40)
set @BaseMetal='18K'

SELECT   @BaseMetal AS 'BaseMetal', tbl.Columm1,tbl.Columm2, tbl.Columm3 from tbl