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 2000 Forums
 Transact-SQL (2000)
 Pivoting in SQL server 2000

Author  Topic 

thangavelu_arun@yahoo.com
Starting Member

8 Posts

Posted - 2009-02-18 : 13:02:50
Hi,

I am in urgent need of the query.

For example i have

Table name : tblTemp
----------------------
ColumnName | Datatype |
----------------------
GenTime | Datetime |
FileType | Char(5) |
-----------------------

The values are
Gentime FileType
----------------------------------
'1/20/2009 6:00:00 PM' 'ABC'
'1/20/2009 6:00:00 PM' 'PQR'
'1/20/2009 6:00:00 PM' 'XYZ'
'1/21/2009 6:00:00 PM' 'ABC'
'1/21/2009 6:00:00 PM' 'XYZ'

The result expected is

Gentime FileType_ABC FileType_PQR FileType_XYZ
--------------------------------------------------------------
'1/20/2009 6:00:00 PM' true true true
'1/21/2009 6:00:00 PM' true false true

Can anyone please give me the query for the above output?


Thanks,
Velu

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-18 : 13:09:27
[code]
SELECT Gentime,
MAX(CASE WHEN FileType='ABC' THEN 1 ELSE 0 END) AS FileType_ABC,
MAX(CASE WHEN FileType='PQR' THEN 1 ELSE 0 END) AS FileType_PQR,
MAX(CASE WHEN FileType='XYZ' THEN 1 ELSE 0 END) AS FileType_XYZ
FROM tblTemp
GROUP BY Gentime
[/code]
Go to Top of Page

thangavelu_arun@yahoo.com
Starting Member

8 Posts

Posted - 2009-02-18 : 14:53:38
Thanks a lot,

It really helped.
Go to Top of Page
   

- Advertisement -