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)
 Using CASE in View

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2004-05-11 : 12:54:58
Hi.

i have a view with several columns, that is fine
but now i ihave to use DATEDIF in a Date Column thas has NULL value
using CASE in QueryAnalize works fine, but View
doesnt allow to use CASE.

Are there other options?

tks

Clages
From Rio de Janeiro

SELECT * ,
CASE
WHEN DUP_DTPGTO IS NULL
THEN
DATEDIFF (DAY, GETDATE(),DUP_VENCTO )
END as Atraso,
DATEDIFF (DAY, DUP_DTPGTO, DUP_VENCTO) as AtrasoPgto
from ViewDuplicat

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-05-11 : 13:08:10
Try this:

SELECT * ,
COALESCE(DUP_DTPGTO, DATEDIFF (DAY, GETDATE(),DUP_VENCTO) AS Atraso,
DATEDIFF (DAY, DUP_DTPGTO, DUP_VENCTO) as AtrasoPgto
from ViewDuplicat


COALESCE returns the first non-null item in that select list.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page
   

- Advertisement -