Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Calculation in SELECT quert (SQL SERVER 2005)

Status
Not open for further replies.

katrina11

Technical User
Apr 30, 2011
108
I know how to do it in SAS but have no idea how to implement this conditional calculation in SQL Server 2005
if LOSp=. then LOSp=0;
HospDischDate=intnx('DtDay', Admitdt, LOSp)
The thing is that I would like to calculate HospDischDate=AdmitDt + LOSP in the body of Select Query:

select
field1
,field2
,??????
into desiredTable
FROM myTable

LOS is a length of Stay in hospital(in days) while
two other fields are dates . For ex. Admitdt looks like 2010-11-16 00:00:00

How can I implement the SELECT query with calculation?

Any help would greatly appreciated

Katrin
 
Look at CASE statements in BOL,

something like
Code:
select Field1, Field2,
case when LOSp = '.' then AdmitDt 
else dateadd(day, cast(LOSp as int), AdmitDt) END as HospDischDate

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top