This should be a fairly simple question but I know very little about SQL. I have a database which has the following fields:
client_id
scheduled_amount
deposit_amount
message_code_id
note_text
system_date
Now I wish to select all the records that are less than 1 year old from when the SQL statement is run. I know I should use DateDiff
, anyone got any ideas?
Thanks
We can use DATEADD() function like below to Subtract Years from DateTime in Sql Server. DATEADD() functions first parameter value can be year or yyyy or yy, all will return the same result.
The EXTRACT() function returns a number which represents the year of the date. The EXTRACT() function is a SQL standard function supported by MySQL, Oracle, PostgreSQL, and Firebird. If you use SQL Server, you can use the YEAR() or DATEPART() function to extract the year from a date.
Answer: C. TRUNCATE is a DDL command. It removes the records from the table without any condition. It is not the part of any ongoing transaction and an uncommitted transaction in the session is committed after TRUNCATE is executed.
select * from MyTable where MyDate > DATEADD(year, -1, GetDate())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With