| Author |
Topic |
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-06-12 : 21:17:15
|
| How can i insert a if-else condition in a select statement or is there a way to specify a condition within a select statement?Any reply is really appreciated..thank you..shemay |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-06-12 : 21:21:41
|
| Have details? Checked case clause? |
 |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-06-12 : 21:47:42
|
| I already tried the case clause but it won't work in my script.The scenario is this if the column DateofTransfer is > EndDate, DateofTransfer should be equal EndDate,else DateofTransfer remains the same.shemay |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-06-12 : 22:41:43
|
| What was your statement with case? |
 |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-06-12 : 22:45:02
|
| SELECT a.m0020_pat_id, a.M0040_PAT_LNAME + ', ' + a.M0040_PAT_FNAME + ' ' + a.M0040_PAT_MI as patientName, a.M0030_START_CARE_DT as socdate,M0906_DC_TRAN_DTH_DT as transferdate,M0906_DC_TRAN_DTH_DT+14 as DueDate = Case when M0906_DC_TRAN_DTH_DT+14 > a.EffectiveDate_End then M0906_DC_TRAN_DTH_DT+14 = a.EffectiveDate_End else M0906_DC_TRAN_DTH_DT+14 end d.name facilityName, e.FacilityTypeNameFunnyfrog |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-06-12 : 23:23:21
|
| Tried this?SELECT a.m0020_pat_id, a.M0040_PAT_LNAME + ', ' + a.M0040_PAT_FNAME + ' ' + a.M0040_PAT_MI as patientName,a.M0030_START_CARE_DT as socdate,M0906_DC_TRAN_DTH_DT as transferdate,DueDate = Case M0906_DC_TRAN_DTH_DT+14 when M0906_DC_TRAN_DTH_DT+14 > a.EffectiveDate_End then M0906_DC_TRAN_DTH_DT+14 = a.EffectiveDate_End else M0906_DC_TRAN_DTH_DT+14 end d.name facilityName, e.FacilityTypeName |
 |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-06-12 : 23:32:15
|
| Do i neeed to set parameters before using the due date column in the case when statement?Funnyfrog |
 |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-06-12 : 23:42:16
|
| if i will place the case when statement in the where clause,would that still be applicable?Funnyfrog |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-06-12 : 23:57:50
|
| Use subquery for search condition? |
 |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-06-13 : 00:09:29
|
| would it be alright to do this? WHERE DueDate = Case M0906_DC_TRAN_DTH_DT+14 when DueDate > EffectiveDate_End then M0906_DC_TRAN_DTH_DT+14 = EffectiveDate_End else M0906_DC_TRAN_DTH_DT+14 endFunnyfrog |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-13 : 08:37:56
|
| http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=84942MadhivananFailing to plan is Planning to fail |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-06-13 : 10:50:00
|
| Not sure what you want, where clause is for search condition but your code doesn't look like search criteria. |
 |
|
|
|