Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2006
    Posts
    58

    Unanswered: ABout SELECT Syntax?

    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.

  2. #2
    Join Date
    Nov 2005
    Location
    San Francisco, CA
    Posts
    506
    Code:
    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,
    Code:
    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
    Last edited by rudra; 11-07-06 at 03:06.
    Success is the ability to go from one failure to another with no loss of enthusiasm.
    - Sir Winston Churchill
    Joydeep

  3. #3
    Join Date
    Aug 2006
    Posts
    58
    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!

  4. #4
    Join Date
    Nov 2005
    Location
    San Francisco, CA
    Posts
    506
    Read this ...LINK
    And please read the whole topic( you must scroll down) and then everything will be clear to you.
    Success is the ability to go from one failure to another with no loss of enthusiasm.
    - Sir Winston Churchill
    Joydeep

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •