Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
So my question is I have a lot of data on our SQL server and I think is going to take a while to download all that data, for example how can I download only 2018 data?
Thanks!
Hi Jhonatan,
try using below expressoon
select *
from dbo.DATABASE
where A.Date >= Convert(datetime, '2018-01-01' )
Many Thanks
Karthik
by putting where clause
where Date>= '01/01/2018'
please check the date format as well before putting this clause
-- Avoid Using Functions in WHERE Clause --
DECLARE @TableVariable TABLE (Units INT, Account INT, BudgetPeriod NVARCHAR(20), MyDate DATE)
INSERT INTO @TableVariable
VALUES
(12, 1234,'BudgetPeriod01','01/02/2018'),
(34, 2345,'BudgetPeriod02','02/03/2018'),
(45, 1234,'BudgetPeriod01','01/02/2017'),
(67, 2345,'BudgetPeriod02','02/03/2017')
/* If you want the best performance DON’T implement your solution this way.
Here is why: https://www.mssqltips.com/sqlservertutorial/3204/avoid-using-functions-in-where-clause/ */
Select *
From @TableVariable
Where YEAR(MyDate)=2018
GO
/*
--This is the correct method
Select *
From @TableVariable
Where MyDate>='01/01/2018'
*/
Thank you!