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 2000 Forums
 SQL Server Development (2000)
 Table Transformation
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3451 Posts

Posted - 08/02/2007 :  05:32:41  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
Hi all,

I need to transform the following table...

CREATE TABLE #VendorProductAggregateAmounts (
	vpId					INT
	, employeeId				INT
	, employeeCost				MONEY DEFAULT NULL
	, employerCost				MONEY DEFAULT NULL
	, taxFreeAmount				MONEY DEFAULT NULL

with data in the form....

INSERT INTO #VendorProductAggregateAmounts
	SELECT 1,  201, 0.0000,   0.0000,   0.0000 UNION ALL
	SELECT 7,  201, 712.8900, 475.2500, 0.0000 UNION ALL
	SELECT 9,  201, 0.0000,   0.0000,   0.0000 UNION ALL
	SELECT 12, 201, 84.6600,  84.6600,  0.0000

into a #results table with 1 line per employeeId with 3 columns for each vpid (column names to have the form (description + (employee / employer / taxFreeAmount) (description taken from the vendorProduct table (referenced by vpId)

prototype like....

employeeId || vpId.descrip (employee) || vpId.description (employer) || vpid.description (taxFreeAllowance) || .........

Is there any better way to do this than setting up a cursor (or loop) to alter a #results table adding the descriptions+(employee/employer etc) columns using dynamic sql and then perform a second loop to insert the data into the as yet unknown column names using more dynamic sql.

I know that the I really shouldn't be doing this in SQL it's a task for a client application but I've got to work with what I've got to work with.

Any help would be appreciated!


Edited by - Transact Charlie on 08/02/2007 05:34:02
  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.02 seconds. Powered By: Snitz Forums 2000