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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query Help

Author  Topic 

DotNetDeveloper
Starting Member

2 Posts

Posted - 2008-06-04 : 01:25:09
hai,
I have two tables
slno courseid cname
1 1 be
2 2 bsc
(remember) slno is autogenerated.
table 2
courseid year
1 2008
1 2006
2 2007
2 2006

I have to join this two table and bind it to gridview like
slno cname year year
1 1 2008 2006
2 2 2007 2006

i tried innerjoin,but im getting o/p like
slno cname year
1 be 2008
2 be 2006
like that.I have to repeat that year column according to data in table

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-04 : 01:30:32
Use the new PIVOT operator available in SQL Server 2005.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-04 : 01:31:35
How do you expect to get 1,2,.. for cname field? the table data shows be,bsc,...
Go to Top of Page

DotNetDeveloper
Starting Member

2 Posts

Posted - 2008-06-04 : 01:41:49
how to write PIVOT Query.
Can you guide me?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-04 : 01:44:55
Yes.

1) Write PIVOT in your query window
2) Hightlight the PIVOT word
3) Press SHIFT+F1
4) Read the chapter about PIVOT operator on Books Online



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -