Home > database >  Subtraction problem, SQL, time validity of batch query
Subtraction problem, SQL, time validity of batch query

Time:11-20

There is a table of a field for the period of validity field

Want to is to want to query data
The query of data to be expired within 30 days from the day,


With the following statement
Select * from AIC_Base_Card where DateDiff (dd, CA_EndDatetime, getdate ()) & lt;=30

But found within 30 days earlier than the day log but subtract data also found out, what method just query is greater than the current time after time to minus the expiration time and door group 30 days a way

consult

CodePudding user response:

query of data to be expired within 30 days from the day,


It depends on 30 days, how do you define, want accurate to seconds,


Advice into such, better performance (this column if added index, can be used to)

Where CA_EndDatetime & lt;=getdate () - 30

CodePudding user response:

reference 1st floor selling fruit net reply:
query of data to be expired within 30 days from the day,


It depends on 30 days, how do you define, want accurate to seconds,


Advice into such, better performance (this column if added index, can be used to)

Where CA_EndDatetime & lt;=getdate () - 30

Today is 5.27, for example, I want to check the validity of data within the range of 5.27 ~ 6.27, 30 days of data

CodePudding user response:

Select
Convert (varchar (10), getdate (), 121) C1,
Convert (varchar (10), dateadd (month 1, getdate ()), 121) C2,
Convert (varchar (10), dateadd (month 1, getdate () + 1), 121) C3



C1 C2 C3
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The 2020-05-27 2020-06-27 2020-05-27

Line (1) affected


Completion time: 2020-05-27 T08:44:43. 1865329 + 08:00

CodePudding user response:

The upstairs,

CodePudding user response:

For example,

reference 3 floor selling fruit net reply:
select
Convert (varchar (10), getdate (), 121) C1,
Convert (varchar (10), dateadd (month 1, getdate ()), 121) C2,
Convert (varchar (10), dateadd (month 1, getdate () + 1), 121) C3



C1 C2 C3
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The 2020-05-27 2020-06-27 2020-05-27

Line (1) affected


Completion time: 2020-05-27 T08:44:43. 1865329 + 08:00


Sorry
According to your statement I do have this effect
But my actual data for the
CARDS as of the date
0001 the 2020-05-01
0002 the 2020-06-03
0003 the 2020-06-25
0004 the 2020-05-20

I want in the 2020-05-27 performs the query results for
0002 the 2020-06-03
0003 the 2020-06-25
Back in 2020-05-27 for the node within 30 days overdue data

How do you achieve this