July 15, 2010 at 4:30 am
Hi All
I need help, i a have table with our security certificates and there's a coloumn with expiry date. What i need is to check which certificate will be expiring in a months time then send a notification to security. the date format is 2010/02/04 yyyy/mm/dd
email body script i do have.
Tx
It's better to fail while trying, rather than fail without trying!!!
July 16, 2010 at 8:14 pm
Something like this:
SELECT * FROM dbo.YourTable
WHERE YourColumn =
CAST(DATEPART(year,DATEADD(month,1,GETDATE())) as VARCHAR(4))+'/'
+REPLICATE('0', 2 - DATALENGTH(CAST(DATEPART(month,DATEADD(month,1,GETDATE())) as VARCHAR(2))))
+CAST(DATEPART(month,DATEADD(month,1,GETDATE())) as VARCHAR(2))+'/'
+REPLICATE('0', 2 - DATALENGTH(CAST(DATEPART(day,DATEADD(month,1,GETDATE())) as VARCHAR(2))))
+CAST(DATEPART(day,DATEADD(month,1,GETDATE())) as VARCHAR(2))
July 16, 2010 at 9:55 pm
I don't believe that it needs to be quite that complex. Unless I'm somehow missing the big picture, something like the following should do...
SELECT * FROM dbo.YourTable
WHERE YourColumn BETWEEN GETDATE() AND DATEADD(mm,1,GETDATE())
If you made this mistake of storing the date as a varchar in that format, you may have to use something like the following:
SELECT * FROM dbo.YourTable
WHERE REPLACE(YourColumn,'/','') BETWEEN GETDATE() AND DATEADD(mm,1,GETDATE())
--Jeff Moden
Change is inevitable... Change for the better is not.
July 16, 2010 at 9:58 pm
There ar emany ways to do it. This is just an example for the date in character format
July 16, 2010 at 10:00 pm
magasvs (7/16/2010)
There ar emany ways to do it. This is just an example for the date in character format
Understood. So why not pick a simple way?
--Jeff Moden
Change is inevitable... Change for the better is not.
July 17, 2010 at 8:53 am
That was Friday's madness 🙂
SELECT * FROM YourTable
WHERE convert (datetime,YourColumn) =
DATEADD(month,1,convert (datetime,convert(varchar(10), getdate(), 101), 101))
July 18, 2010 at 11:52 am
magasvs (7/17/2010)
That was Friday's madness 🙂SELECT * FROM YourTable
WHERE convert (datetime,YourColumn) =
DATEADD(month,1,convert (datetime,convert(varchar(10), getdate(), 101), 101))
Heh... madness indeed.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 19, 2010 at 12:51 am
Thanks!!
It's better to fail while trying, rather than fail without trying!!!
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply