Tuesday 15 June 2010

sql - Retrieve dates between two given dates -



sql - Retrieve dates between two given dates -

this current sql query:

declare @fromdate datetime=null, @todate datetime=null set @fromdate = '10/11/2014' set @todate = '11/11/2014' select * tbluser ((convert(varchar(10), createddate, 103) between convert(varchar(10), @fromdate, 103) , convert(varchar(10), @todate, 103))

but 2 records after executing query, i.e. 11/11/2014, , have 4 records in table on all:

how can desired records between date range when both , dates given , when both null. doing wrong?

the convert statements using not necessary. next work:

select * tbluser createddate between @fromdate , @todate

also, maintain in mind not specifying time, defaults midnight. so, todate '11/11/2014 00:00:00'. results of query should single row (the first row), because others occur after midnight on 11/11/2014.

you stated fromdate , todate null. in case should set them lower , upper boundary values, appropriate, homecoming desired results.

sql sql-server-2008

No comments:

Post a Comment