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
 General SQL Server Forums
 New to SQL Server Programming
 Dynamic columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ranjit.ileni
Posting Yak Master

India
181 Posts

Posted - 08/26/2011 :  05:32:20  Show Profile  Reply with Quote

create table #BaseTable
(
	 Id int identity
	,Metadata Varchar(100)
)
insert into #BaseTable
select 'tiffin' union all
select 'lunch'  union all
select 'snacks' union all
select 'dinner' union all
select 'Tea'   


create table #temp
(
	 Id int identity
	,Rid int
	,Metadata Varchar(100)
	,PaxCount int 
	,comment varchar(100)
)
insert into #temp
select 10,'tiffin',1,'needed' union all
select 10,'lunch',2,'not needed' union all
select 10,'snacks',35,'not interested' union all
select 10,'dinner',5,'ok'  union all  
select 11,'dinner',4,'ok' 


select * from #BaseTable

select * from #temp

Here #BaseTable have metadata values ,we can enter multiple rows for metadata
and #temp Table uses the metadata as a foreignkey ref.

expected output:
columns names should be dynamic:
Rid tiffin	comment	lunch	comment	snacks	comment	dinner	comment	Tea	comment

Rid tiffin comment lunch comment snacks comment dinner comment Tea comment
10 1 needed 2 not needed 35 not interested 5

--Ranjit

visakh16
Very Important crosS Applying yaK Herder

India
47136 Posts

Posted - 08/26/2011 :  06:36:25  Show Profile  Reply with Quote
see
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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