Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two temporary table #CoreUtilizationForRole1 and #RoleID2Details. I want to insert values into a third temp table using these two temp table. Below are the table Structure of both the Temp table.

SQL
create table #CoreUtilizationForRole1(roleid int,SupervisorName varchar(50),ImmediateSupervisor varchar(50),UserECode varchar(50),UserName nvarchar(250),Designation varchar(250),TimeSpent float,ActivityName varchar(250))

create table #RoleID2Details(UserECode varchar(50),UserName nvarchar(250))


in #CoreUtilizationForRole1 table I had generated a report and stored in it. #RoleID2Details contains data as mentioned below in the query:-

SQL
insert into #RoleID2Details
    select distinct Userecode,Username from #CoreUtilizationForRole1 where roleid=2

Now I want to loop through each records of #RoleID2Details and insert data into a third temp table while joining from #CoreUtilizationForRole1. AcTually I need data in a particular described format and due to that, this looping is required so that I insert data into third temp table as per my requirement and then using a simple select statement I will display it. Please help me to do this.
Posted
Comments
Oshtri Deka 30-Apr-13 3:04am    
Which particular format?
Do you really need to use cursor, i.e. loop?
Is there particular reason for using three tables or it was your idea?

1 solution

Please, see this: Adding Rows by Using INSERT and SELECT[^].

Another solution is to use: CTE[^]. You did not provide enough information, so i can't show you an example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900