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. string parameter treate as colunm name in execute procedure

string parameter treate as colunm name in execute procedure

Scheduled Pinned Locked Moved Database
csharphelp
6 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
    Unknown Ajanabi
    wrote on last edited by
    #1

    set nocount on declare @ResultSql varchar(8000) declare @anurag varchar(20) set @anurag='anurag' Set @ResultSql='SELECT distinct a.RegID,a.companyname, b.LocalityName FROM Registration AS a INNER JOIN Locality AS b ON a.LocalityID = b.LocalityID inner join pincode as p on a.pincodeid=p.pincodeid WHERE(a.CityID =1) and a.companyname='+@anurag Create Table #Tbl_Myphonedata ( Id numeric IDENTITY PRIMARY KEY, regid numeric, companyname varchar(30), localityname varchar(30) ) --Fill the temp table with the reminders set @ResultSql = 'select regid,companyname,localityname from( ' + @ResultSql + ' ) OO' Insert Into #Tbl_Myphonedata ( regid,companyname,localityname ) exec ( @ResultSql ) select * from #Tbl_Myphonedata drop table #Tbl_Myphonedata in above procedure parameter @anurag is string type parameter when i execute exec(@ResultSql) @anurag trate as colunm name but it is a simple parameter please help me :(

    no knowledge in .net

    A 1 Reply Last reply
    0
    • U Unknown Ajanabi

      set nocount on declare @ResultSql varchar(8000) declare @anurag varchar(20) set @anurag='anurag' Set @ResultSql='SELECT distinct a.RegID,a.companyname, b.LocalityName FROM Registration AS a INNER JOIN Locality AS b ON a.LocalityID = b.LocalityID inner join pincode as p on a.pincodeid=p.pincodeid WHERE(a.CityID =1) and a.companyname='+@anurag Create Table #Tbl_Myphonedata ( Id numeric IDENTITY PRIMARY KEY, regid numeric, companyname varchar(30), localityname varchar(30) ) --Fill the temp table with the reminders set @ResultSql = 'select regid,companyname,localityname from( ' + @ResultSql + ' ) OO' Insert Into #Tbl_Myphonedata ( regid,companyname,localityname ) exec ( @ResultSql ) select * from #Tbl_Myphonedata drop table #Tbl_Myphonedata in above procedure parameter @anurag is string type parameter when i execute exec(@ResultSql) @anurag trate as colunm name but it is a simple parameter please help me :(

      no knowledge in .net

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      You need to enclose it in quotes so that sql server knows it is a value not a column. Better still, used a parameterised query - faster and less prone to sql injections.

      Bob Ashfield Consultants Ltd

      U 1 Reply Last reply
      0
      • A Ashfield

        You need to enclose it in quotes so that sql server knows it is a value not a column. Better still, used a parameterised query - faster and less prone to sql injections.

        Bob Ashfield Consultants Ltd

        U Offline
        U Offline
        Unknown Ajanabi
        wrote on last edited by
        #3

        but i don't know how to enclose string parameter in execute procedure

        no knowledge in .net

        M A J 3 Replies Last reply
        0
        • U Unknown Ajanabi

          but i don't know how to enclose string parameter in execute procedure

          no knowledge in .net

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          That's called learning - look into parameterised queries in BOL.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • U Unknown Ajanabi

            but i don't know how to enclose string parameter in execute procedure

            no knowledge in .net

            A Offline
            A Offline
            Ashfield
            wrote on last edited by
            #5

            Well then, now is a good time to learn - google is your friend :)

            Bob Ashfield Consultants Ltd

            1 Reply Last reply
            0
            • U Unknown Ajanabi

              but i don't know how to enclose string parameter in execute procedure

              no knowledge in .net

              J Offline
              J Offline
              Jon_Boy
              wrote on last edited by
              #6

              Just because you don't know how to enclose a parameter or willing to try the parameterized method like Ashfield suggested, you should bash people on the review. People maybe less likely to help in the future.

              Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

              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