Using SQL Server 2012, and the new date type (not dateTime) I created the next procedure:
CREATE PROC Test(@StartDate date ,@EndDate date)
AS
DECLARE @Temp TABLE([ID] int, [Date] date)
INSERT INTO @Temp SELECT 1, CONVERT(date,'31/12/2012',103)
INSERT INTO @Temp SELECT 2, CONVERT(date,'01/10/2012',103)
INSERT INTO @Temp SELECT 3, CONVERT(date,'01/01/2012',103)
SELECT * FROM @Temp WHERE [Date] BETWEEN @StartDate AND @EndDate
When I run this stored procedure I get the next error indicating the date format of the parameter:
Incorrect syntax near '/'.
Please what should be done ?
For one, your date shouldn’t have a
/in it. But it also needs to be enclosed in quotes. Try:The reason it needs to be enclosed in quotes is, if you don’t use quotes, your “date” is interpreted as a mathematical expression, e.g.:
The reason your date shouldn’t have a
/in it is becausem/d/yandd/m/yare unsafe formats that can be interpreted differently depending on language and other settings.And finally, if you are calling this procedure from C#, why are you passing strings and not properly typed parameters?