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. update temp table with results from sub query (actually it is a function)

update temp table with results from sub query (actually it is a function)

Scheduled Pinned Locked Moved Database
questionannouncementdatabase
6 Posts 3 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.
  • J Offline
    J Offline
    joost versteegen
    wrote on last edited by
    #1

    hi, i am having trouble with a query. how can i update a temp table with results from sub query (actually it is a function)? this works:

    UPDATE @TEMP
    SET
    formula\_name = (SELECT name FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no)),
    formula\_version = (SELECT version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no))
    FROM @TEMP
    

    but i want something like this:

    UPDATE  @TEMP 
    SET formula\_name = r.name, 
    formula\_version = r.version
    FROM (SELECT name, version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no) r
    

    thanks.

    Z Richard DeemingR 2 Replies Last reply
    0
    • J joost versteegen

      hi, i am having trouble with a query. how can i update a temp table with results from sub query (actually it is a function)? this works:

      UPDATE @TEMP
      SET
      formula\_name = (SELECT name FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no)),
      formula\_version = (SELECT version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no))
      FROM @TEMP
      

      but i want something like this:

      UPDATE  @TEMP 
      SET formula\_name = r.name, 
      formula\_version = r.version
      FROM (SELECT name, version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no) r
      

      thanks.

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      Treat it the same as a table

      UPDATE @temp
      SET formula_name = r.name, formula_version = r.version
      FROM dbo.fn_GetFormulaForJob(wo_id, oper_id,seq_no) r

      Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

      J 1 Reply Last reply
      0
      • Z ZurdoDev

        Treat it the same as a table

        UPDATE @temp
        SET formula_name = r.name, formula_version = r.version
        FROM dbo.fn_GetFormulaForJob(wo_id, oper_id,seq_no) r

        Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

        J Offline
        J Offline
        joost versteegen
        wrote on last edited by
        #3

        thanks. i tried it, but i get the error 'Cannot call methods on table'. too bad. my original looks so inefficient, but it will have to do i guess.

        1 Reply Last reply
        0
        • J joost versteegen

          hi, i am having trouble with a query. how can i update a temp table with results from sub query (actually it is a function)? this works:

          UPDATE @TEMP
          SET
          formula\_name = (SELECT name FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no)),
          formula\_version = (SELECT version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no))
          FROM @TEMP
          

          but i want something like this:

          UPDATE  @TEMP 
          SET formula\_name = r.name, 
          formula\_version = r.version
          FROM (SELECT name, version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no) r
          

          thanks.

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          How about:

          UPDATE T
          SET formula_name = r.name, forumula_version = r.verion
          FROM @TEMP As T
          CROSS APPLY dbo.fn_GetFormulaForJob(T.wo_id, T.oper_id, T.seq_no) As r;

          Using APPLY | FROM (Transact-SQL) - SQL Server | Microsoft Docs[^] SQL Server CROSS APPLY and OUTER APPLY[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          J 2 Replies Last reply
          0
          • Richard DeemingR Richard Deeming

            How about:

            UPDATE T
            SET formula_name = r.name, forumula_version = r.verion
            FROM @TEMP As T
            CROSS APPLY dbo.fn_GetFormulaForJob(T.wo_id, T.oper_id, T.seq_no) As r;

            Using APPLY | FROM (Transact-SQL) - SQL Server | Microsoft Docs[^] SQL Server CROSS APPLY and OUTER APPLY[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            J Offline
            J Offline
            joost versteegen
            wrote on last edited by
            #5

            wow, ok, i will try it first thing in the morning. thanks.

            1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              How about:

              UPDATE T
              SET formula_name = r.name, forumula_version = r.verion
              FROM @TEMP As T
              CROSS APPLY dbo.fn_GetFormulaForJob(T.wo_id, T.oper_id, T.seq_no) As r;

              Using APPLY | FROM (Transact-SQL) - SQL Server | Microsoft Docs[^] SQL Server CROSS APPLY and OUTER APPLY[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              J Offline
              J Offline
              joost versteegen
              wrote on last edited by
              #6

              this works! Thanks.

              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