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
 Pivot is not working

Author  Topic 

divyaram
Posting Yak Master

180 Posts

Posted - 2010-01-12 : 05:36:03
hi all,


select Title,[1] as user1,[19] as user2,[25]as user3 from
(select First_Name, Last_Name,Email_ID,Title from FIS_User) u
pivot(count(Position_ID)for Industry_ID in ([1],[19],[25]))as pv
order by pv.First_Name


i have done like this , but its throwing error

Msg 207, Level 16, State 1, Line 4
Invalid column name 'Position_ID'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Industry_ID'.


but all this columns are there in the table.... then why its throwing error like this

Regards,
Divya

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 05:41:30
quote:
Originally posted by divyaram

hi all,


select Title,[1] as user1,[19] as user2,[25]as user3 from
(select First_Name, Last_Name,Email_ID,Title,Position_ID,Industry_ID from FIS_User) u
pivot(count(Position_ID)for Industry_ID in ([1],[19],[25]))as pv
order by pv.First_Name


i have done like this , but its throwing error

Msg 207, Level 16, State 1, Line 4
Invalid column name 'Position_ID'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Industry_ID'.


but all this columns are there in the table.... then why its throwing error like this

Regards,
Divya


you've not included the columns in derived table
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-01-12 : 05:56:51
simply u can use like this
select Title,[1] as user1,[19] as user2,[25]as user3 from
FIS_User
pivot(count(Position_ID)for Industry_ID in ([1],[19],[25]))as pv
order by pv.First_Name
Go to Top of Page

divyaram
Posting Yak Master

180 Posts

Posted - 2010-01-12 : 06:45:48
thank u all its wrking fine.... now i understood my mistake in query thank u alll

Regards,
Divya
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 06:47:33
quote:
Originally posted by divyaram

thank u all its wrking fine.... now i understood my mistake in query thank u alll

Regards,
Divya


welcome
Go to Top of Page
   

- Advertisement -