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 2000 Forums
 SQL Server Development (2000)
 Select query

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2005-11-11 : 10:43:58
I have the folowing select query, which checks number of days left or over due.

When it is over due i want to show the days in parenthesis like this: (28) instead saying 28 days over due.

Can you please help.

**********************************
select project, task,
[days] = CASE WHEN due_date < GetDate()
THEN CONVERT(varchar(20), DATEDIFF(Day, due_date, GetDate()))
+ ' days over due'
ELSE CONVERT(varchar(20), DATEDIFF(Day, GetDate(), due_date))
+ ' days'
END
FROM @MyTable
*********************************

Thank you very much for the information.

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-11 : 11:02:10
select project, task,
[days] = CASE WHEN due_date < GetDate()
THEN '(' + CONVERT(varchar(20), DATEDIFF(Day, due_date, GetDate()))
+ ')'
ELSE CONVERT(varchar(20), DATEDIFF(Day, GetDate(), due_date))
+ ' days'
END
FROM @MyTable

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -