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
 Transact-SQL (2005)
 i wan to include null in select statement

Author  Topic 

cwfontan
Yak Posting Veteran

87 Posts

Posted - 2008-12-09 : 16:47:41
the following takes 3 columns in the same record unpivots and compares the three columns taking the max of the 3.. I need to select if all three columns are null as well.. right now it only retunrns records that have a date. Thanks in advance.



WITH DateCompare(formID, formNumber, description, policyUrl, Date, userID) AS
(/* Convert each record from a horizontal to vertical format */
SELECT u.formID, u.formNumber, u.description, u.policyUrl, u.Date, u.userID
FROM policyManagementDB.dbo.formList AS tbl UNPIVOT (Date FOR Col IN (tbl .effectiveDate, tbl .reviewDate, tbl .revisedDate)) AS u), DateMax(formID, formNumber, description, policyUrl, date, userID) AS
(/* Derive the maximum date for each ID */
SELECT DISTINCT formID, formNumber, description, policyUrl, MAX(Date) OVER (PARTITION BY formID), userID
FROM DateCompare)
/* Only retrieve records older than 11 months from today */
SELECT DISTINCT datemax.formID, datemax.formNumber, datemax.description, datemax.policyUrl, CONVERT(CHAR(24),datemax.date,101) as Date, datemax.userID, h.email
FROM DateMax INNER JOIN
[10.56.200.241].helpDeskDB.dbo.users AS h ON DATEMAX.userid = h.userID
WHERE Date < DATEADD(MONTH, - 11, GETDATE());
   

- Advertisement -