SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case Date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

stwp86
Starting Member

USA
42 Posts

Posted - 10/02/2012 :  10:00:45  Show Profile  Reply with Quote
Hey Everyone . . .

Quick question. I would like to add a case statement to my select, so that when the date field is one of the 4 earilest dates a temporary column writes out "Baseline" and when it is not one of the 4 earliest dates it writes out "Trending". Here is my first attempt:


SELECT n.Client_mnemonic,round((([Total Elapsed Time (sec)]/WeeklyUserCount)/60.0),2) AS "Total Time" ,m.WeekMinDate as "Work Week", n.Group_Type,
CASE WHEN m.weekmindate Top 4 THEN 'Baseline' 
             ELSE 'Trending'
           END as "BarType"


I dont really understand Case statements that well, so I am a bit perplexed on how to get the four earliest dates. I thought something like TOP 4, but that didn't seem to work out, or I did it wrong.

Any thoughts?

Thanks!

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/02/2012 :  10:28:14  Show Profile  Reply with Quote
m.weekmindate Top 4 is not a valid syntax. i think what you need is this


SELECT *,
CASE WHEN Seq <= 4 THEN 'Baseline' 
             ELSE 'Trending'
           END as "BarType",
...

FROM
(
SELECT n.Client_mnemonic,round((([Total Elapsed Time (sec)]/WeeklyUserCount)/60.0),2) AS "Total Time" ,m.WeekMinDate as "Work Week", n.Group_Type,ROW_NUMBER() OVER (ORDER BY m.weekMinDate) AS Seq
...

)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

stwp86
Starting Member

USA
42 Posts

Posted - 10/02/2012 :  10:37:28  Show Profile  Reply with Quote
Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/02/2012 :  10:41:09  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000