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 store result of exec(query) values in to a temp table

how to store result of exec(query) values in to a temp table

Scheduled Pinned Locked Moved Database
databasehelptutorialquestion
7 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 I have a small problem if any budy know please reply me I have the following sql code when i will execute it i will get a some data in a single column Now i want to insert those data into a temp table.But the problem is @Role_Idv is a column in table [admin].[cm_tb_005].Which i am passing dynamically. If iam taking only this much select tb001_id FROM [admin].[cm_tb_005] WHERE '+ @Role_Idv +'='1'' The above code will not work.If iam doing like this exec('select tb001_id FROM [admin].[cm_tb_005] WHERE '+ @Role_Idv +'=''1''') It is working.Now i want to store the resulted values in a temp table.So that i can select the values from temp table for other purposes. This is the code which iam trying now which is excuting but how can i store the resultant values in a temp table SET QUOTED_IDENTIFIER ON declare @res1 nvarchar(500) declare @TempMenuId nvarchar(800) declare @Role_Idv varchar(50) set @Role_Idv='R25' DECLARE @TempMenuIdTable TABLE(RowIndex INT IDENTITY,Menu_Id INT ) set @res1='select tb001_id FROM [admin].[cm_tb_005] WHERE '+ @Role_Idv +'=''1''' select @res1 exec(@res1) Regard's Veeresh

    i want to join this group

    A 1 Reply Last reply
    0
    • V veereshIndia

      Hi All I have a small problem if any budy know please reply me I have the following sql code when i will execute it i will get a some data in a single column Now i want to insert those data into a temp table.But the problem is @Role_Idv is a column in table [admin].[cm_tb_005].Which i am passing dynamically. If iam taking only this much select tb001_id FROM [admin].[cm_tb_005] WHERE '+ @Role_Idv +'='1'' The above code will not work.If iam doing like this exec('select tb001_id FROM [admin].[cm_tb_005] WHERE '+ @Role_Idv +'=''1''') It is working.Now i want to store the resulted values in a temp table.So that i can select the values from temp table for other purposes. This is the code which iam trying now which is excuting but how can i store the resultant values in a temp table SET QUOTED_IDENTIFIER ON declare @res1 nvarchar(500) declare @TempMenuId nvarchar(800) declare @Role_Idv varchar(50) set @Role_Idv='R25' DECLARE @TempMenuIdTable TABLE(RowIndex INT IDENTITY,Menu_Id INT ) set @res1='select tb001_id FROM [admin].[cm_tb_005] WHERE '+ @Role_Idv +'=''1''' select @res1 exec(@res1) Regard's Veeresh

      i want to join this group

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

      Assuming you are using SQL Server 2005 (probably works on 2000 but not tested) here is a simple example: create table #temp(employeeid bigint) exec('insert into #temp select employeeid from employee') select * from #temp drop table #temp Hope this helps

      Bob Ashfield Consultants Ltd

      V 1 Reply Last reply
      0
      • A Ashfield

        Assuming you are using SQL Server 2005 (probably works on 2000 but not tested) here is a simple example: create table #temp(employeeid bigint) exec('insert into #temp select employeeid from employee') select * from #temp drop table #temp Hope this helps

        Bob Ashfield Consultants Ltd

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

        Hi Sir, Iam using Sql 2000.Its not working.If there is any solution please rely me. Regard's Veeresh

        i want to join this group

        A 1 Reply Last reply
        0
        • V veereshIndia

          Hi Sir, Iam using Sql 2000.Its not working.If there is any solution please rely me. Regard's Veeresh

          i want to join this group

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

          I've just had it tested on SQL 2000 and it worked. How is it failing? Whats the error?

          Bob Ashfield Consultants Ltd

          V 1 Reply Last reply
          0
          • A Ashfield

            I've just had it tested on SQL 2000 and it worked. How is it failing? Whats the error?

            Bob Ashfield Consultants Ltd

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

            One minut sir.I will check once again.Thanks for replying. Regard's Veeresh

            i want to join this group

            V 1 Reply Last reply
            0
            • V veereshIndia

              One minut sir.I will check once again.Thanks for replying. Regard's Veeresh

              i want to join this group

              V Offline
              V Offline
              veereshIndia
              wrote on last edited by
              #6

              Hi, Thanks sir i got it really thanks a lot Regard's Veeresh

              i want to join this group

              A 1 Reply Last reply
              0
              • V veereshIndia

                Hi, Thanks sir i got it really thanks a lot Regard's Veeresh

                i want to join this group

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

                You are welcome

                Bob Ashfield Consultants Ltd

                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