Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: A tough one... (for me)


Message #1 by Brian Smith <Brian.Smith@R...> on Mon, 18 Jun 2001 17:32:47 -0500
My problem is simple:

I need to return all customers with active product licenses, and what all
products they have.  Each of these queries are simple enough, but how would
I do both together, with all results on a single line?

In short, how can I:
	A) Rotate a single column of undefined length (i.e., length
determined by query results)
	B) Append rotated results onto same record/line as company info

Basically, from two tables CUSTOMERS and LICENSES (one -> many), I need to
produce:

+------+------+-------+-------+-------+
  CUST | ADDR | PROD1 | PROD2 | PROD3  
+------+------+-------+-------+-------+
 Alpha | Road | No    | Yes   | No
 Beta  | Road | Yes   | No    | No
 Delta | Road | Yes   | No    | Yes

Is there some way to create a temp table with dynamically defined columns,
and just fill it up?

For now I'm just writing the logic in a VBScript file to dump data into an
Excel sheet, but I'd love to just run this in SQLServer's Query Analyzer.
Any hints or tips on accomplishing that (regardless of complexity) would be
appreciated!

Cheers,
Brian

  Return to Index