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 2012 Forums
 Transact-SQL (2012)
 How to convert days into number.

Author  Topic 

NguyenL71
Posting Yak Master

228 Posts

Posted - 2013-12-03 : 17:17:00
If the user want to archive data older than 30 than @numberofDay should convert into date like 11/03/2013.
They want to pass in days as int and the process should convert that into day.

Any help would greatly appreciate.

Declare @NumberofDay INT = 30

-- No

@NumberofDay should be something like '11/03/2013'


DELETE FROM MyBilling
OUTPUT deleted.[__$start_lsn], deleted.[__$seqval], deleted.[__$operation], deleted.[__$update_mask], deleted.[BillingDetail_ID]
INTO ArchiveAudit.MyBilling_CT ( [__$start_lsn], [__$seqval], [__$operation], [__$update_mask], [BillingDetail_ID]

WHERE (CONVERT(CHAR(8), [Effective_date], 112) < @NumberofDay ) -- This some how become '11/03/2013'

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-12-03 : 17:28:03
Do you want a date that is @numberofDays less than today?


declare @numberOfDay int; set @numberOfDay = 30
select dateadd(day, datediff(day, 0, getdate()), -@numberOfDay)

OUTPUT:
2013-11-03 00:00:00.000


So you probably want:

WHERE Effective_date < dateadd(day, datediff(day, 0, getdate()), -@numberOfDay)


Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-03 : 23:43:38
quote:
Originally posted by NguyenL71

If the user want to archive data older than 30 than @numberofDay should convert into date like 11/03/2013.
They want to pass in days as int and the process should convert that into day.

Any help would greatly appreciate.

Declare @NumberofDay INT = 30

-- No

@NumberofDay should be something like '11/03/2013'


DELETE FROM MyBilling
OUTPUT deleted.[__$start_lsn], deleted.[__$seqval], deleted.[__$operation], deleted.[__$update_mask], deleted.[BillingDetail_ID]
INTO ArchiveAudit.MyBilling_CT ( [__$start_lsn], [__$seqval], [__$operation], [__$update_mask], [BillingDetail_ID]

WHERE (CONVERT(CHAR(8), [Effective_date], 112) < @NumberofDay ) -- This some how become '11/03/2013'


see
http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -