请教:如何将用变量表示的字段值,赋值给另一个变量?
表a: 年度 1月 2月 3月
2006 100 500 800
.... ... ... ...
变量a1等于1月或2月或3月
取年度等于2006的变量a1表示的字段值,赋值给另一个变量a2。
请给出sql范例语句。
谢谢!
表a: 年度 1月 2月 3月
2006 100 500 800
.... ... ... ...
变量a1等于1月或2月或3月
取年度等于2006的变量a1表示的字段值,赋值给另一个变量a2。
请给出sql范例语句。
谢谢!
insert A select 2006,100,500,800declare @para1 int,@para2 int
select @para1=[1月] from A
select @para1
select @para2=@para1
select @para2
select top 1 @para1=[1月] from A where 年度=2006
select @para1
select @para2=@para1
select @para2
insert into tb select 2006,100,500,800
godeclare @month nvarchar(20)
set @month=N'1月'
declare @year int
set @year=2006
declare @t int
declare @sql nvarchar(4000)
set @sql=N'select @t=['+cast(@month as nvarchar)+'] from tb where 年份='+cast(@year as nvarchar)
exec sp_executesql @sql,N'@t int output',@t output
select @tdrop table tb--这个意思?
select top 1 @a1=[你的月份] from A where 年度=2006
--select @a1
select @a2=@para1
--select @a2
谢谢:xeqtr1982(Visual C# .NET)结果正确。