Click here to Skip to main content
12,998,759 members (73,124 online)
Rate this:
Please Sign up or sign in to vote.
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 20:20pm
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

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170622.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
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