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
 General SQL Server Forums
 New to SQL Server Programming
 Query Help

Author  Topic 

MTSPEER
Starting Member

6 Posts

Posted - 2013-06-03 : 14:48:25
Hey guys,

I have 3 fields I want to display. The name of the person[Name], Date Mailed[Date Mailed], and Date Received[Date Received]. I want to display the records that don't have information in them and only if it's been 30 days or more. I wrote this code here:

Select * from Sheet1
Where [Date Received] is NULL

But that only returns all the blank fields. I want to display the ones that are blank and have been 30 days..I want to keep the blank records within the 30 day period.

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-06-03 : 14:52:00
30 days check should be on DateMailed? If so you can have an other check as e.g.

Select * from Sheet1
Where [Date Received] is NULL
AND DateMailed between dateadd(mm,-1,getdate()) and getdata()

Cheers
MIK
Go to Top of Page

MTSPEER
Starting Member

6 Posts

Posted - 2013-06-03 : 14:56:43
It says Undefined function 'getdate' in the expression
Go to Top of Page

MTSPEER
Starting Member

6 Posts

Posted - 2013-06-03 : 14:58:21
BTW-I just want to display the blank records that are past the 30 day period of Date Mailed
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-04 : 01:32:22
quote:
Originally posted by MTSPEER

It says Undefined function 'getdate' in the expression


-- Small typo
Select * from Sheet1
Where [Date Received] is NULL
AND DateMailed between dateadd(mm,-1,getdate()) and getdate()


--
Chandu
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-04 : 01:40:42
quote:
Originally posted by MTSPEER

BTW-I just want to display the blank records that are past the 30 day period of Date Mailed


use this condition for past 30 days mails
WHERE [Date Mailed] > = DATEADD( DD, -30 , DATEDIFF(DD, 0, GETDATE()))

--
Chandu
Go to Top of Page
   

- Advertisement -