RRM
RRM

Reputation: 3451

What does "SELECT X=[column] FROM [table] exactly does"?

I wanted to set a variable in SQL by

SELECT @myVariable=myColumn FROM myTable WHERE ...

But by mistake I wrote it without @

SELECT myVariable=myColumn FROM myTable WHERE ...

It seems that it is valid, there isn't any error in syntax, although variable of course isn't set.

So what does such instruction exactly do?

Upvotes: 0

Views: 524

Answers (2)

user212514
user212514

Reputation: 3130

You're right that it is valid syntax and it names the output column as myVariable and populates the column with the content of myColumn.

Upvotes: 0

Siyual
Siyual

Reputation: 16917

This sets myVariable as an alias for myColumnn. It's essentially the same as:

Select  MyColumn As MyVariable
From    MyTable
Where   ...

Upvotes: 4

Related Questions