how to store result of exec(query) values in to a temp table
-
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
-
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
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 helpsBob Ashfield Consultants Ltd
-
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 helpsBob Ashfield Consultants Ltd
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
-
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
-
I've just had it tested on SQL 2000 and it worked. How is it failing? Whats the error?
Bob Ashfield Consultants Ltd
One minut sir.I will check once again.Thanks for replying. Regard's Veeresh
i want to join this group
-
One minut sir.I will check once again.Thanks for replying. Regard's Veeresh
i want to join this group
Hi, Thanks sir i got it really thanks a lot Regard's Veeresh
i want to join this group
-
Hi, Thanks sir i got it really thanks a lot Regard's Veeresh
i want to join this group