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. how i set Table name and Column name dynmicalyy in Ms sql sp

how i set Table name and Column name dynmicalyy in Ms sql sp

Scheduled Pinned Locked Moved Database
csharpsharepointdatabasesql-server
3 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.
  • R Offline
    R Offline
    r_mohd
    wrote on last edited by
    #1

    hi all i have develping an application in vb.net with mssql express 2005, now i want to fetch records from a table with different conditions i want to use a parameter as a column name in which i want to pass differnt field names and an other parametr to pass condition value. here is the Sp by which i trying to fecth the data but could not.... pl help me CREATE PROCEDURE TEMP1EMPINFO --CREATE PROCEDURE TEMP1EMPINF ( @Tbl_col_name varchar(100), @Col_val varchar(100) ) AS Begin Select * from table where @tbl_col_name= @col_val end GO thanks

    rmshah Developer

    M N 2 Replies Last reply
    0
    • R r_mohd

      hi all i have develping an application in vb.net with mssql express 2005, now i want to fetch records from a table with different conditions i want to use a parameter as a column name in which i want to pass differnt field names and an other parametr to pass condition value. here is the Sp by which i trying to fecth the data but could not.... pl help me CREATE PROCEDURE TEMP1EMPINFO --CREATE PROCEDURE TEMP1EMPINF ( @Tbl_col_name varchar(100), @Col_val varchar(100) ) AS Begin Select * from table where @tbl_col_name= @col_val end GO thanks

      rmshah Developer

      M Offline
      M Offline
      Marek Grzenkowicz
      wrote on last edited by
      #2

      You will have to build a SELECT statement dynamically and then execute it using sp_executesql[^]. But as far as I know it's not very good performancewise. Google for "dynamic SQL" and read about it. How many different values of @Tbl_col_name will you be using? Wouldn't it be easier to create a separate SP for each case?

      1 Reply Last reply
      0
      • R r_mohd

        hi all i have develping an application in vb.net with mssql express 2005, now i want to fetch records from a table with different conditions i want to use a parameter as a column name in which i want to pass differnt field names and an other parametr to pass condition value. here is the Sp by which i trying to fecth the data but could not.... pl help me CREATE PROCEDURE TEMP1EMPINFO --CREATE PROCEDURE TEMP1EMPINF ( @Tbl_col_name varchar(100), @Col_val varchar(100) ) AS Begin Select * from table where @tbl_col_name= @col_val end GO thanks

        rmshah Developer

        N Offline
        N Offline
        Niraj_Silver
        wrote on last edited by
        #3

        Sure you can try this One... Declare @qry VarChar(1000), @clmname VarChar(100), @tabname VarChar(100) Set @qry = (Select @clmname from @tabname) Exec(@qry) hAVE A nICE DAY.... bY... :-D

        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