Need dates that are less than 50 days away from now

I have this script that needs to pull records that are less than 50 days away form current date. This is a warning system about some cards that will expire in less than 50 days from current.

The script seems to be working for the most part but for some reason I am getting a few dates that are 2014-06-30.. That date is NOT less than 50 days away. I will post the code and the results.
create table ##tokens  (user34 nvarchar(200), DateDeath date)
declare @user34 nvarchar(200), @dateDeath nvarchar(200)
declare @sql nvarchar(2000)
declare @warningdate date
declare @expiresdate date
declare @serialNBR nvarchar(20)

--set the warning date variable. This says if its less than 50 days away
 set @warningdate = DATEADD(day,50,getdate())
 --SET @warningdate =   getdate() +50
SELECT @warningdate

INSERT  ##tokens (user34, DateDeath)
SELECT  m.NameReg,
        (SELECT TOP 1
        FROM    dbo.secureToken
        WHERE   usedBy34 = s.usedBy34
        ORDER BY dbo.secureToken.[DateDeath] DESC
                   ) DateDeath
FROM    AssetManagement.dbo.secureToken s
        INNER JOIN dbo.Users_Master m ON s.usedBy34 = m.user34
WHERE   s.DateDeath < @warningdate

select * from ##tokens

user34            DateDeath
Shawn Hess	2014-06-30
Caroline Foust	2010-05-31
Sarah Hanson	2010-05-31
Allison Jones	2010-05-31
Troy Baskin	2010-04-30
John Haeger	2010-05-31
Kerry Johnson	2010-04-30
Jennifer Bolkcom	2014-03-31
Patricia Barrow	2010-05-31
Toni Oosting	2010-05-31
Dana Leonard	2010-05-31
Tiffanie Markus	2010-05-31
Sheri Mersch	2010-05-31
Julia Love	2010-04-30
Brandy Martin	2010-05-31
Barbara Thomas	2010-04-30
Rita Hatfield	2014-03-31
Jason Williams	2010-05-31
Wendy Pinson	2010-05-31
Mythili Shastry	2013-05-31
Mange Li	2010-04-30
Anne Gary	2010-04-30
Marsha Baskette	2010-04-30
Julienne Martinson	2014-03-31
Stacie Thomas	2010-05-31

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this:
* From YourTableName
Where DateDiff(dd,YourDateColumn,getDate()) = 50
The field that you check "s.DateDeath < @warningdate" is NOT the same with the one that you insert in the temporary table. The one that you insert is the top 1 which means the first record
dboyd02Author Commented:
halfboddprince: this returned no records I tried < as well. It returned 198 records where I know there are about 22 that are expiring. Thanks though.

Mdagis. I am checking into yours now.
May try something like:

INSERT  ##tokens (user34, DateDeath)
Select NameReg, DateDeath
SELECT  m.NameReg,
        (SELECT TOP 1
        FROM    dbo.secureToken
        WHERE   usedBy34 = s.usedBy34
        ORDER BY dbo.secureToken.[DateDeath] DESC
                   ) DateDeath
FROM    AssetManagement.dbo.secureToken s
        INNER JOIN dbo.Users_Master m ON s.usedBy34 = m.user34
) DT
WHERE   DateDeath < @warningdate

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dboyd02Author Commented:
That worked perfectly!!!!!! Thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.