Return modified datetime data in Select...Case

I have a stored procedure that returns appointment data into a form.  Everything was working fine but I've been tasked with the following:

1. If the appointment is flagged as appAllDay = 1, the appointment start time (appDate) needs to display with a different time.  The physical data isn't touched or changed.

For example, 2010-02-05 08:00:00.000 needs to display as 2010-02-05 11:00:00.000 in my appTime column shown below.

The appDate field is a datetime column so I'm not sure if this is even possible.  Any assistance would be appreciated.

SELECT dbo.dbAppointments.appID,
(case appAllDay when 0 then appDate else
****
end) as appTime
FROM        
dbo.dbAppointments
WHERE dbo.dbAppointments.feeusrid = 7459
smsstechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tlovieCommented:
Am I missing something, or would this work?

SELECT dbo.dbAppointments.appID,
(case appAllDay when 0 then appDate else
dateadd(hh, 11, convert(datetime, convert(varchar(8), appDate, 112), 112))
end) as appTime
FROM        
dbo.dbAppointments
WHERE dbo.dbAppointments.feeusrid = 7459

convert it from a date to a varchar, back to a date (to remove the time portion), then add 11 hours to it.  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kevin CrossChief Technology OfficerCommented:
I agree, that approach should work, i.e., grabbing date at midnight and adding hours/minutes back to get to the time of day you want. As an aside, if you are using SQL Server 2008, there are new data types for DATE and TIME, separately; therefore, you may want to see if those are a better fit for your design. A NULL TIME for example might symbolize all day or at least you can always make time whatever you want based on appAllDay.

Kevin
0
smsstechAuthor Commented:
Thanks.  Fantastic work.

I don't deal with datetime in SQL very often so manipulation was new to me.  I appreciate the sample and the SQL Server 08 notes.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.