开发者

Can we assign more than one variable in on SELECT Statement in SQL Server? [closed]

开发者 https://www.devze.com 2023-03-09 10:55 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, 开发者_运维问答overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, 开发者_运维问答overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Can we assign more than one variable in on SELECT Statement ?

Like:

SELECT @variable1 = c1+c2  , @variable2 = c1-c2  from someView

it dosn't work in SQL Server

please help

Thanks...


Yes, SQL Server allows this

CREATE TABLE fish (c1 int, c2 int)
INSERT fish VALUES (1, 2)
GO
DECLARE @v1 int, @v2 int
SELECT
   @v1 = c1-c2, @v2 = c1+c2
FROM
  fish

SELECT @v1, @v2

So, you are not giving us full information:

  • query
  • data
  • error message
0

精彩评论

暂无评论...
验证码 换一张
取 消