Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. What is Wrong with the Following Query

What is Wrong with the Following Query

Scheduled Pinned Locked Moved Database
csharpdatabasecomhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    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

    Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

    T 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      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

      Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

      T Offline
      T Offline
      Tobias Schoenig
      wrote on last edited by
      #2

      Vuyiswa wrote:

      Update sde.Property_Backup p3 set p3.Attrib_code = p12.Attrib_code

      Why are you including sde.Property_Backup? If p3 is a table, it would be right to write: Update p3 set p3.Attrib_code = p12.Attrib_code.

      V 1 Reply Last reply
      0
      • T Tobias Schoenig

        Vuyiswa wrote:

        Update sde.Property_Backup p3 set p3.Attrib_code = p12.Attrib_code

        Why are you including sde.Property_Backup? If p3 is a table, it would be right to write: Update p3 set p3.Attrib_code = p12.Attrib_code.

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        hi Thanks for your reply i wrote it like this 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 p2 set p2.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 and It gives me an Error

        Msg 208, Level 16, State 1, Line 10
        Invalid object name 'p2'.
        /pre>.

        the Problem happenes on the Update. Thanks

        Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

        T 1 Reply Last reply
        0
        • V Vimalsoft Pty Ltd

          hi Thanks for your reply i wrote it like this 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 p2 set p2.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 and It gives me an Error

          Msg 208, Level 16, State 1, Line 10
          Invalid object name 'p2'.
          /pre>.

          the Problem happenes on the Update. Thanks

          Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

          T Offline
          T Offline
          Tobias Schoenig
          wrote on last edited by
          #4

          How is your table called? p2? If p2 is the name of your table try the following update statement: UPDATE p2 SET p2.Attrib_code = p1.Attrib_code INNER JOIN p1 ON p1.lis_key = p2.lis_key WHERE Substring(p2.func_key,1,5) = 'GEOSS' AND P1.active = 1

          V 1 Reply Last reply
          0
          • T Tobias Schoenig

            How is your table called? p2? If p2 is the name of your table try the following update statement: UPDATE p2 SET p2.Attrib_code = p1.Attrib_code INNER JOIN p1 ON p1.lis_key = p2.lis_key WHERE Substring(p2.func_key,1,5) = 'GEOSS' AND P1.active = 1

            V Offline
            V Offline
            Vimalsoft Pty Ltd
            wrote on last edited by
            #5

            Thanks i have Used a Cursor to achieve this DECLARE @CUR_LIS_KEY VARCHAR(20), @CUR_ATTRIB_CODE VARCHAR(12) DECLARE PARENT_CURSOR CURSOR FOR SELECT LIS_KEY, ATTRIB_CODE FROM SDE.PROPERTY_Summary P1 WHERE EXISTS(SELECT 1 FROM SDE.PROPERTY_Summary P2 WHERE P2.FUNC_KEY LIKE 'GEOSS%' AND P2.LIS_KEY = P1.LIS_KEY And p2.Attrib_code is Null And p2.Archive_Date is Null ) OPEN PARENT_CURSOR FETCH NEXT FROM PARENT_CURSOR INTO @CUR_LIS_KEY, @CUR_ATTRIB_CODE WHILE @@FETCH_STATUS = 0 BEGIN UPDATE SDE.PROPERTY_Summary SET ATTRIB_CODE = @CUR_ATTRIB_CODE WHERE FUNC_KEY LIKE 'GEOSS%' AND LIS_KEY = @CUR_LIS_KEY FETCH NEXT FROM PARENT_CURSOR INTO @CUR_LIS_KEY, @CUR_ATTRIB_CODE END DEALLOCATE PARENT_CURSOR Thanks for your Help

            Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups