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 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.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