Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
jhona1737
Contributor III
Contributor III

How to get data from SQL from specific range of dates

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!

4 Replies
karthikoffi27se
Creator III
Creator III

Hi Jhonatan,

try using below expressoon

select * 
from dbo.DATABASE
where A.Date >= Convert(datetime, '2018-01-01' )


Many Thanks

Karthik

shiveshsingh
Master
Master

by putting where clause

where Date>= '01/01/2018'

please check the date format as well before putting this clause

wdchristensen
Specialist
Specialist

-- 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'

*/

jhona1737
Contributor III
Contributor III
Author

Thank you!