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.
| Author |
Topic |
|
anandchinnappan
Starting Member
7 Posts |
Posted - 2010-03-15 : 14:22:07
|
| Dear Experts,My view has the following three columns.1, Start Date2. End Date3. Balance.I need an SQL statement which has to check if EndDate is less than the Current date and balance is above zero. If so, it assumes the last date of the job is already over, outstanding materials not yet been returned. Hence it has to return 'Pending'. If EndDate is greater than current date, it means final date for completion of the process is yet to come. So the task is in progress, hence it has to return 'Progress'. If the balance is Zero, all materials connected with the task have been received either as a FG or as Raw Materials. So it has to return, 'Completed'. I need a singe SQL Statement for this.Please help me.Thanks in advance.RegardsAnand |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-03-15 : 14:31:15
|
| You can use case statements.exampleselect case when enddate<currentdate and balance >0 then 'Pending' else ur next case condition & so on.PBUH |
 |
|
|
Ehan
Starting Member
19 Posts |
Posted - 2010-03-15 : 14:34:27
|
| something like thisSELECT StartDate,EndDate,Balance,Status = CASE WHEN EndDate < GETDATE() AND Balance > 0 THEN 'Pending' WHEN EndDate > GETDATE() THEN 'Progress' WHEN Balance = 0 THEN 'Completed' ENDFROM tab |
 |
|
|
anandchinnappan
Starting Member
7 Posts |
Posted - 2010-03-15 : 14:58:46
|
thanks experts.I got the solution through ur answer.RegardsAnand    |
 |
|
|
|
|
|