当前位置: 代码迷 >> Sql Server >> 问个列名无效的有关问题
  详细解决方案

问个列名无效的有关问题

热度:84   发布时间:2016-04-27 12:03:11.0
问个列名无效的问题
举个简单的列子

select d1=1,d2=2,d3=d1+d2 from tablea

会显示d1,d2无效,还有什么其他办法能够直接表达d3是d1,d2的和?

------解决方案--------------------
select d1=1,d2=2,d3=1+2 from tablea


------解决方案--------------------
那就是d3 = 1 + 2了,换成了列的话就是
select field1 as d1,field2 as d2,(field1 + field2) as d3 from tablea

------解决方案--------------------
SQL code
select d1=1,d2=2,d3=1+2 from tablea
------解决方案--------------------
declare @d1 int;
declare @d2 int;
declare @d3 int;
select @d1=1,@d2=2,@[email protected][email protected]
select @d1,@d2,@d3
------解决方案--------------------
SQL code
select *, d3=d1+d2  from(select d1=1,d2=2  from table) a
  相关解决方案