SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

archive
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!

tm
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'
union
select 'Bundling' , 'Jay' , 'Jen'


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


Result:

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

archive
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  
 New 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.05 seconds. Powered By: Snitz Forums 2000