Tuesday, September 2, 2014

Date Range as Parameter

Erm, unless I'm missing what the OP is asking for, he wants to pass a string like '07/21/2014-07/21/2014' as a parameter, and then select all the rows from his table which fall within that date range, 07/21/2014 to 07/21/2014, which is what the example I posted does.



DECLARE @string VARCHAR(20) = '7/22/2014-7/29/2014'

Represents the inbound parameter.



select * from mytable where theDate between @startDate and @endDate

Represents his actual query, where the string has been split into two dates, and used with a between.

No comments:

Post a Comment