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 |
|
Rayman
Starting Member
39 Posts |
Posted - 2010-09-22 : 15:03:01
|
| I have the following table with the data:Database_date11/30/08 1:52 AM12/31/08 9:22 AM3/17/08 11:22 AM1/4/09 11:22 PMI would like to determine how to produce the sql code to display the information by the following output;Month AM PM1 November YES NO2 December NO YES3 March YES NO4 January NO YESAny suguestions would be appreciated. Thank youTerry L King |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-09-22 : 15:09:36
|
| DECLARE @Table TABLE (database_date datetime)insert into @Table SELECT '11/30/08 1:52 AM' UNION SELECT '12/31/08 9:22 AM' UNION SELECT '3/17/08 11:22 AM' UNION SELECT '1/4/09 11:22 PM'SELECT datename(month,database_date) as [Month] ,CASE WHEN datepart(hour,database_date) >=12 THEN 'YES' ELSE 'NO' END as PM ,CASE WHEN datepart(hour,database_date) <12 THEN 'YES' ELSE 'NO' END as AMFROM @tableJimEveryday I learn something that somebody else already knew |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-23 : 12:37:20
|
| I assume the december values in sample is a typo as i see time as AM but it has just opposite values in output------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|