Hi,everyone.
Today I met with a interesting problem. According to Microsoft SQL SERVER 2005 BOOKS ONLINE, there is following SELECT Syntax:
(1) SELECT @.local_variable (Transact-SQL)
For example:
DECLARE @.i int
SELECt @.i=100
(2) SELECt QUERY statement:
SELECT [ ALL | DISTINCT ]
[ TOP expression [ PERCENT ] [ WITH TIES ] ]
<select_list>
<select_list> ::=
....
For example,
[AdventureWorks]
SELECT * FROM DatabaseLog
To my surprise, in the given project, I met this kind of SELECT statement,
DECLARE @.w_type varchar(10), @.i varchar(30)
SELECT @.i='3'
SELECT @.w_type='OLTPNORMAL' WHERE @.i IN ('0','1','2','3','4','5','9',)
SELECT @.w_type
The result is:
OLTPNORMAL
However, I have not met with the kind of SELECT statement before. Please give me some advice. Thank you in advance.DECLARE @.w_type varchar(10), @.i varchar(30)
SELECT @.i='3'
SELECT @.w_type='OLTPNORMAL' WHERE @.i IN ('0','1','2','3','4','5','9')
SELECT @.w_type
The result is:
OLTPNORMAL
Thats absolutely okay,
SELECT @.i='3' -- assigning value '3' to @.i
SELECT @.w_type='OLTPNORMAL' WHERE @.i IN ('0','1','2','3','4','5','9') -- Assigning @.w_type='OLTPMORMAL' if where clause satisfies,here it is satisfying bcoz @.i='3'
SELECT @.w_type -displaying @.w_type|||Thank you,Rudra.
Here I have gotten the same result as yours. However, the kind of SQL Synax "SELECT...@.local_variable ...WHERE..." is not introduced in SQL SERVER 2005 in Microsoft SQL SERVER 2005 BOOKS ONLINE. So when I found this statement I felt surprised. Can you give me some advice to look for some introductions about the kind of SQL Synax ?
Thank you very much!|||Read this ...LINK (http://msdn2.microsoft.com/en-us/library/ms189484.aspx)
And please read the whole topic( you must scroll down) and then everything will be clear to you.
No comments:
Post a Comment