Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL2000 SQL-server-2005 SQL , +
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.
 
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:-
 
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 29-Apr-13 21:20pm
Comments
Oshtri Deka at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 165
2 PIEBALDconsult 150
3 BillWoodruff 148
4 DamithSL 140
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100