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)
 How to calculate the age with checking a condition

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2006-01-13 : 15:20:47
How to calculate the age with an if condition under select query

If isdate(ToContractorDate) = 1 then
DATEDIFF(Day, TAB_ccsNetSU.PDReceivedDate, ToContractorDate) AS Age
elseif isdate(ToContractorDate) = 0 then
DATEDIFF(Day, TAB_ccsNetSU.PDReceivedDate, GETDATE()) AS Age
end if


I would like to include the above if condition to AGE in the following query can you please help: this is in my stored proc where i am using dynamic string.

SET @SQLStatement = 'SELECT TAB_ccsNetSU.SUNumber, TAB_ccsNetSU.SUTitle,
DATEDIFF(Day, TAB_ccsNetSU.PDReceivedDate, GETDATE()) AS Age
FROM TAB_ccsNetSU INNER JOIN
TAB_ccsNetActions ON TAB_ccsNetSU.SUID = TAB_ccsNetActions.ModuleRecordID ' + @SQLJoin

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-01-13 : 16:29:05
Are you looking for CASE?

select case
when isdate(ToContractorDate) = 1 then DATEDIFF(Day, TAB_ccsNetSU.PDReceivedDate, ToContractorDate)
else DATEDIFF(Day, TAB_ccsNetSU.PDReceivedDate, GETDATE())
end as Age


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -