Got more questions? Find advice on: ASP | XML | Regular Expressions | Windows
in Search
Welcome to SqlAdvice Sign in | Join | Help

What is Wrong with the Following Query

Last post 04-08-2009, 3:59 PM by Grady Christie. 1 replies.
Sort Posts: Previous Next
  •  02-01-2008, 6:39 AM 39179

    What is Wrong with the Following Query

    hi all

    hi all i have the Following Query

    if Exists(select * from sde.Property_Backup p1
    where substring(p1.func_key,1,5)='GEOSS'
    aND Exists (select p2.Property_ID,p2.Lis_key,p2.Func_key,
    p2.Attrib_code
    from sde.Property_Backup p2
    where p2.func_key = 'PV000000'
    And p1.lis_key = p2.lis_key
    And P2.aCTIVE =1))
    begin

    Update sde.Property_Backup p3
    set p3.Attrib_code = p12.Attrib_code
    where p2.lis_key = p1.lis_key
    and substring(p2.func_key,1,5)='GEOSS'
    And P1.aCTIVE =1
    end

     And i get the Following Error when run it

     

    "Msg 170, Level 15, State 1, Line 10
    Line 10: Incorrect syntax near 'p3'."

    what is wrong


    Thanks

     

     

  •  04-08-2009, 3:59 PM 52028 in reply to 39179

    Re: What is Wrong with the Following Query

    I don't think you can use aliases in an UPDATE statement so try taking

    out the "p3".   And check "p12.Attrib_Code". Should that be 

    "p1.Attrib_Code" instead?

    Try this:

    Update sde.Property_Backup

    set .Attrib_code = p1.Attrib_code
    where p2.lis_key = p1.lis_key
    and substring(p2.func_key,1,5)='GEOSS' 
    And P1.aCTIVE =1
    end

     

    -- Hope it helps.  Grady Christie

View as RSS news feed in XML