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. Web Development
  3. ASP.NET
  4. Table name as parameter

Table name as parameter

Scheduled Pinned Locked Moved ASP.NET
database
7 Posts 4 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.
  • U Offline
    U Offline
    User 1804931
    wrote on last edited by
    #1

    Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V

    P P U 3 Replies Last reply
    0
    • U User 1804931

      Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V

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

      If you are passing table_name as a parameter to stored procedure and using there is a specific syntax which should be followed and used. I dont remeber exaclt how I had done this. As well there are some limitations with the same. Padvit

      1 Reply Last reply
      0
      • U User 1804931

        Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V

        P Offline
        P Offline
        Plunging_Falcon
        wrote on last edited by
        #3

        You can use dynamic sql to do that. For instance, if you have a procedure that gets column_in as column parameter and table_in as table parameter, then you can write something like this: (Oracle SQL, haven't tested elsewhere) OPEN ref_cur1 FOR 'SELECT ' || column_in || ' FROM ' || table_in; I think if you are using SQL SERVER then you should just omit the OPEN...FOR part.

        1 Reply Last reply
        0
        • U User 1804931

          Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V

          U Offline
          U Offline
          utsav_verma
          wrote on last edited by
          #4

          Hope it'll help CREATE PROCEDURE [DBO].[GetFieldByID] (@FieldName varchar(50), @TableName varchar(50), @IDVal int) AS declare @IDField varchar(50) set @IDField = @TableName + 'ID' exec('select ' + @FieldName + ' from ' + @TableName + ' where ' + @IDField + ' = ' + @IDVal) GO UTSAV

          U 2 Replies Last reply
          0
          • U utsav_verma

            Hope it'll help CREATE PROCEDURE [DBO].[GetFieldByID] (@FieldName varchar(50), @TableName varchar(50), @IDVal int) AS declare @IDField varchar(50) set @IDField = @TableName + 'ID' exec('select ' + @FieldName + ' from ' + @TableName + ' where ' + @IDField + ' = ' + @IDVal) GO UTSAV

            U Offline
            U Offline
            User 1804931
            wrote on last edited by
            #5

            Hi, It is working fine, thank you very much. Regards, Chakravarthy.v

            1 Reply Last reply
            0
            • U utsav_verma

              Hope it'll help CREATE PROCEDURE [DBO].[GetFieldByID] (@FieldName varchar(50), @TableName varchar(50), @IDVal int) AS declare @IDField varchar(50) set @IDField = @TableName + 'ID' exec('select ' + @FieldName + ' from ' + @TableName + ' where ' + @IDField + ' = ' + @IDVal) GO UTSAV

              U Offline
              U Offline
              User 1804931
              wrote on last edited by
              #6

              Hi, I tested it but it is causing some problems, can you please verify this because this query is imp for me. Initially I tested this code only by passing the code then it worked fine. Regards KLAYAN

              U 1 Reply Last reply
              0
              • U User 1804931

                Hi, I tested it but it is causing some problems, can you please verify this because this query is imp for me. Initially I tested this code only by passing the code then it worked fine. Regards KLAYAN

                U Offline
                U Offline
                utsav_verma
                wrote on last edited by
                #7

                wELL THIS CODE IS DAMN TESTED, I GUESS U R MISSING WRONG DATATYPE VALUE ooops, sorry 4 caps lock on, hope u'd not mind ;) UTSAV

                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