Incorrect syntax near the keyword 'as'. while set the value for variable

Answered Incorrect syntax near the keyword 'as'. while set the value for variable

  • Saturday, January 19, 2013 9:55 AM
     
      Has Code

    declare  @Date as datetime
    declare @c as int
    select @Date='01/17/2013'
    select @c =  PD.copies as 'PD_COPIES' from PHeader PH inner  join PDetailsPD on  PH.Po_id=Pd.PD_Po_id

    Hi what s wrong here

    here i am getting error 'Incorrect syntax near the keyword 'as'.


    adil

All Replies

  • Saturday, January 19, 2013 10:08 AM
     
     Answered Has Code

    Try

    select @c =  PD.copies  from PHeader PH inner  join PDetailsPD on  PH.Po_id=Pd.PD_Po_id


    Serg

  • Saturday, January 19, 2013 1:22 PM
     
     Proposed

    When assiging a value to a variable the variable already has a name , since the action is assigning a value and not output you cant give the variable an alias


    Jayanth Kurup - www.enabledbusiness.com

  • Sunday, January 20, 2013 5:06 AM
    Moderator
     
      Has Code

    If you're using a scalar variable to return the result you need to remove AS AliasName part from your query, e.g.

    select @c =  PD.copies  from PHeader PH inner  join PDetailsPD on  PH.Po_id=Pd.PD_Po_id


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog