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 to pass dynamically integer as column name to a query

How to pass dynamically integer as column name to a query

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

    Hi all, declare @str1 varchar(500) declare @str2 varchar(500) declare @str3 varchar(500) declare @str4 varchar(500) select @str1=ud_id from cm_tb_002 where username='admin'; select @str3=role_id from cm_tb_012 where tb012_id=@str1; select @str4=tb001_id from cm_tb_001 where menu_activ = 1 and child_lvl = 0 and [15]='1'; select tb001_id from cm_tb_001 where menu_prnt=@str4; Here i want to pass @str3 to a this query select @str4=tb001_id from cm_tb_001 where menu_activ = 1 and child_lvl = 0 and @str3='1'; but the @str3 column is an bigint column. ex. 15 i.e column name In sql sever this value is storing as [15] as column name. Now i want to pass this value to this query select @str4=tb001_id from cm_tb_001 where menu_activ = 1 and child_lvl = 0 and @str3='1'; Please help me on this.

    i want to join this group

    P 1 Reply Last reply
    0
    • V veereshIndia

      Hi all, declare @str1 varchar(500) declare @str2 varchar(500) declare @str3 varchar(500) declare @str4 varchar(500) select @str1=ud_id from cm_tb_002 where username='admin'; select @str3=role_id from cm_tb_012 where tb012_id=@str1; select @str4=tb001_id from cm_tb_001 where menu_activ = 1 and child_lvl = 0 and [15]='1'; select tb001_id from cm_tb_001 where menu_prnt=@str4; Here i want to pass @str3 to a this query select @str4=tb001_id from cm_tb_001 where menu_activ = 1 and child_lvl = 0 and @str3='1'; but the @str3 column is an bigint column. ex. 15 i.e column name In sql sever this value is storing as [15] as column name. Now i want to pass this value to this query select @str4=tb001_id from cm_tb_001 where menu_activ = 1 and child_lvl = 0 and @str3='1'; Please help me on this.

      i want to join this group

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

      You would need to construct your SQL statement as a string and execute it using the EXEC statement.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      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