Link to home
Start Free TrialLog in
Avatar of ihatelag
ihatelag

asked on

SQL code to get data more than 1 month ago from current date

Hi there,

I need help creating a SQL Select query to get data *more* than one month ago from the current date.

I want to retreive the balance of all customers which = 0 (against the above criteria)

There are 5 columns. CustomerID,  Date, BalanceEur, BalanceUSD, BalanceGBP

(date is in datetime format)

Please can you help me to create the SQL query to get this information

Many thanks

Open in new window

Avatar of Answer_Me
Answer_Me
Flag of India image

try this

SELECT CustomerID,  Date, BalanceEur, BalanceUSD, BalanceGBP
FROM Customers
WHERE Datepart(m,Customers.Date) <Datepart(m,GetDate())
AND Datepart(yyyy,Customers.Date) <Datepart(yyyy,GetDate())

Open in new window

Select CustomerID,  [Date], BalanceEur, BalanceUSD, BalanceGBP
Where BalanceUSD=0  -- any one will do right, since 0 at any conversion=0
  AND [Date] < DateAdd(m, -1, GetDate())
ASKER CERTIFIED SOLUTION
Avatar of imitchie
imitchie
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ihatelag
ihatelag

ASKER

Solid work! Works a treat! Thanks for this!
Thanks for this imitchie, this works great!
Glad I could help :)
Have a good day