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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Complicated Query

Author  Topic 

scottichrosaviakosmos
Yak Posting Veteran

66 Posts

Posted - 2010-10-15 : 12:59:53
I have two tables:
one with name tblmonth and another with name tbldate as follows:
tblmonth:
stdid code jan feb march april may
100 A 10 12 50 21 30
100 B 12 11 9 6 45
101 A 12 65 45 34 23
101 B 34 32 12 56 34

tbldate:
stdid sdate eddate
100 01/02/2010 04/05/2010
101 02/03/2010 04/02/2010

Now, i want my result as following :
stdid eddate A B

100 04/05/2010 if(jan)then feb+mar+april+may feb + mar + april+may
if(feb) then mar+april+may mar+april+may

I have tried pivot for first table
select * from tblmonth
pivot(sum(jan) for jan in([jan],[feb])as t

but i m geting data only for jan and not for feb, march .. etc.
And even after getting all data how can i get my above desired output.




scoo

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 04:35:58
isnt this same as
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=151651

why opening lots of threads for same question?

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

Go to Top of Page
   

- Advertisement -