Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 lookup data difficulties
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 01/29/2013 :  13:22:03  Show Profile  Reply with Quote
I am having trouble joining information from a spreadsheet provided to me by another department with an existing table.
The spreadsheet lays out work queues an employee is responsible for with the queues broken down by client.
The problem is, the client breakdown is done by putting each client in their own field.
So the table looks like this
Queue | ACA | BCR
Needs Review | Rob | Ben
Bundling | Jay | Jen

I have another table that has Queue and Client in their own fields.
Queue | Client
Needs Review | ACA
Needs Review | BCR
Bundling | ACA
Bundling | BCR

I would like to join the data to end up with a table like the following.

Queue | Client | Employee
Needs Review | ACA | Rob
Needs Review | BCR | Ben
Bundling | ACA | Jay
Bundling | BCR | Jen

Is it possible to do this without changing the format of the spreadsheet?

Thank you!

Posting Yak Master

160 Posts

Posted - 01/29/2013 :  14:02:36  Show Profile  Reply with Quote
Below is script to Unpivot the first table and it gives the result as you mentioned..

declare @t table ([Queue] varchar(30) , ACA varchar(10), BCR varchar(10))

insert into @t
select 'Needs Review' ,'Rob' , 'Ben'
select 'Bundling' , 'Jay' , 'Jen'

--Unpivot the table.
SELECT [Queue], Client, Employee
FROM @t) AS p
(Employee FOR Client IN
)AS unpvt


Queue Client Employee
Needs Review ACA Rob
Needs Review BCR Ben
Bundling ACA Jay
Bundling BCR Jen
Go to Top of Page

Starting Member

2 Posts

Posted - 01/30/2013 :  15:51:22  Show Profile  Reply with Quote
That worked wonderfully. Thank you very much.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000