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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-01-22 : 17:03:18
|
| john writes "i have a database with a daypart field which has 1 of six values in it - 'EM','DT','EF','PT','LE' and 'LN'. is there a way i can have sql return a recordset with 6 fields - one for each daypart with the daypart total in it. example: objRec!EM_FIELD = 109, objRec!DT_FIELD = 34.... i have had to use multiple recordsets and would like to use one if i could. thanks." |
|
|
DGMelkin
Starting Member
24 Posts |
Posted - 2002-01-22 : 17:43:14
|
| I'm not quite sure what you mean by daypart total. But, will this work for you:SELECT sum(CASE WHEN daypart = 'EM' THEN 1 ELSE 0 END) as EM_Field, sum(CASE WHEN daypart = 'DT' THEN 1 ELSE 0 END) as DT_Field, sum(CASE WHEN daypart = 'EF' THEN 1 ELSE 0 END) as EF_Field, sum(CASE WHEN daypart = 'PT' THEN 1 ELSE 0 END) as PT_Field, sum(CASE WHEN daypart = 'LE' THEN 1 ELSE 0 END) as LE_Field, sum(CASE WHEN daypart = 'LN' THEN 1 ELSE 0 END) as LN_FieldFROM YourTableYou can replace the 1 for field if you're looking for some other value. Feel free to modify this as needed.-DEdited by - dgmelkin on 01/22/2002 17:47:02 |
 |
|
|
|
|
|