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 2005 Forums
 Transact-SQL (2005)
 Select...stumped with CASE

Author  Topic 

skillilea
Starting Member

15 Posts

Posted - 2009-08-20 : 11:26:55
OK I have two fields starttime and duration.
Starttime= INT from 0-95 (or 12 to 12 on the clock in qtr hours)
Duration is the 15min increment

Here is my problem is starttime falls below 32 (8AM) or starttime + duration is past 75 (6PM) I need to trap it.

Here is what I have

SELECT
CASE starttime WHEN < 32 THEN 32 ELSE starttime END 'as starttime
, CASE duration WHEN startime+duation > 75 THEN (i'm stuck) END 'as duration
, field
, field

FROM ....


The other problem is I probably need to change the durations startime based on < 32 as well.



Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-08-20 : 11:49:08
How do you want to trap it? What do you want to do? Can you explain the logic?

The easy way to write the CASE statemetns is to move the column into the WHEN clause:
SELECT
CASE WHEN starttime < 32 THEN 32 ELSE starttime END AS starttime
, CASE WHEN duration startime+duation > 75 THEN (i'm stuck) END as duration
, field
, field

FROM ....
Go to Top of Page

skillilea
Starting Member

15 Posts

Posted - 2009-08-20 : 12:45:54
It is a calendar application that shows from midnight(0) to 11:45PM (95). When I click a button it defaults to 8AM to 6PM (32)(75). If the dataset has anything from the start time < 32 I need to switch it to 32 if the duration runs past 75 I need to catch it.

Hope that helps.

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-08-20 : 12:51:29
What do you mean by "catch it."

ANother guess:
SELECT
CASE WHEN starttime < 32 THEN 32 ELSE starttime END AS starttime
, CASE WHEN startime+duation > 75 THEN CAST(1)AS BIT
ELSE CAST(0) AS BIT END as IsDurationGreaterThan75
, field
, field

FROM ....
Go to Top of Page
   

- Advertisement -