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. Problem with variable table in SQL

Problem with variable table in SQL

Scheduled Pinned Locked Moved Database
helpdatabase
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
    vuthaianh
    wrote on last edited by
    #1

    Hi all, I've got the following function: CREATE FUNCTION Test(....) RETURNS @ReturnTable TALBE ( ................. ) AS BEGIN DECLARE @MyTable TABLE ( ............. ) INSERT INTO @MyTable SELECT ...... FROM AnotherTable1 Inner Join AnotherTable2 ....... INSERT INTO @ReturnTable SELECT ...... FROM ( SELECT ...... FROM @MyTable WHERE ....... UNION SELECT ...... FROM @Table WHERE ...... ) RETURN END When i call this function, an error message appears "Must declare the scalar variable "@MyTable"." Please help me work out this problem Thanks so much

    P 1 Reply Last reply
    0
    • V vuthaianh

      Hi all, I've got the following function: CREATE FUNCTION Test(....) RETURNS @ReturnTable TALBE ( ................. ) AS BEGIN DECLARE @MyTable TABLE ( ............. ) INSERT INTO @MyTable SELECT ...... FROM AnotherTable1 Inner Join AnotherTable2 ....... INSERT INTO @ReturnTable SELECT ...... FROM ( SELECT ...... FROM @MyTable WHERE ....... UNION SELECT ...... FROM @Table WHERE ...... ) RETURN END When i call this function, an error message appears "Must declare the scalar variable "@MyTable"." Please help me work out this problem Thanks so much

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      vuthaianh wrote:

      CREATE FUNCTION Test(....) RETURNS @ReturnTable TALBE

      There's a typo here.

      vuthaianh wrote:

      SELECT ...... FROM @Table WHERE ......

      Where is @Table declared?

      Paul Marfleet

      V 1 Reply Last reply
      0
      • P pmarfleet

        vuthaianh wrote:

        CREATE FUNCTION Test(....) RETURNS @ReturnTable TALBE

        There's a typo here.

        vuthaianh wrote:

        SELECT ...... FROM @Table WHERE ......

        Where is @Table declared?

        Paul Marfleet

        V Offline
        V Offline
        vuthaianh
        wrote on last edited by
        #3

        Hi pmarfleet, Sorry, i made a typing mistake @Table must be @MyTable But the error does still appear. Thanks again

        P 1 Reply Last reply
        0
        • V vuthaianh

          Hi pmarfleet, Sorry, i made a typing mistake @Table must be @MyTable But the error does still appear. Thanks again

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          I'm still not sure what your problem is, but it may have something to do with how you are using the table variable in your queries. You haven't posted all your code so I can't say for sure, but have a look at this link[^].

          Paul Marfleet

          V 1 Reply Last reply
          0
          • P pmarfleet

            I'm still not sure what your problem is, but it may have something to do with how you are using the table variable in your queries. You haven't posted all your code so I can't say for sure, but have a look at this link[^].

            Paul Marfleet

            V Offline
            V Offline
            vuthaianh
            wrote on last edited by
            #5

            Thanks a lot. The link you gave to me is very useful. I already sovled my problem. Thanks again.

            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