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 2005 Forums
 Analysis Server and Reporting Services (2005)
 Case Statement with IsNull and DateDiff

Author  Topic 

JBourne
Starting Member

1 Post

Posted - 2008-02-27 : 04:29:09
Hi,

Im still getting to grips with ssrs and the varying ways to script.

Im testing on one main column for a datediff with another column, inparticular working out the datediff, Cdate from [O 2 R], as follows;

SELECT FNo, [O R], [O 2 R], CDate, DATEDIFF(day, [O 2 R], CDate) AS 'Time Taken'
FROM vwAllInfo
WHERE (CDate >= @startdate) AND (CDate < @enddate + 1)

This works fine, but when [O 2 R] has blanks CDate needs to calculate the DateDiff from column [O R] instead.

Ive never really used the CASE statement before and really cant get any kind of CASE test to work.

Does anyone have any example script they could provide or give any help please??

Many Thanks
JB

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-27 : 04:52:08
Try:-
SELECT FNo, [O R], [O 2 R], CDate, DATEDIFF(day, CASE WHEN [O 2 R] IS NULL OR [O 2 R]='' THEN [O R] ELSE [O 2 R] END, CDate) AS 'Time Taken'
FROM vwAllInfo
WHERE (CDate >= @startdate) AND (CDate < @enddate + 1)
Go to Top of Page
   

- Advertisement -