developer77
Programmer
Hello everyone,
I have a stored procedure where I declare the start and end dates as datetime.
@StartDate datetime = null,
@EndDate datetime = null,
@SortColumnID Int = null
Then at the end of the stored procedure, I sorted it as follows:
ORDER BY
CASE @SortColumnID
WHEN 1 THEN p1.FirstName
WHEN 2 THEN p1.LastName
WHEN 3 THEN dt.StartDate
WHEN 4 THEN dt.EndDate
ELSE NULL
END,
p1.LastName,
p1.FirstName DESC
I get an error message saying that "Syntax error converting datetime from character string." when I plug in 1 or 2 for the @SortcolumnID. Can you help me convert the dt.StartDate and dt.EndDate to varchar like the others so that I don't get this error. I tried googling for the syntax to convert datetime to varchar but can't seem to find it. Thanks...
I have a stored procedure where I declare the start and end dates as datetime.
@StartDate datetime = null,
@EndDate datetime = null,
@SortColumnID Int = null
Then at the end of the stored procedure, I sorted it as follows:
ORDER BY
CASE @SortColumnID
WHEN 1 THEN p1.FirstName
WHEN 2 THEN p1.LastName
WHEN 3 THEN dt.StartDate
WHEN 4 THEN dt.EndDate
ELSE NULL
END,
p1.LastName,
p1.FirstName DESC
I get an error message saying that "Syntax error converting datetime from character string." when I plug in 1 or 2 for the @SortcolumnID. Can you help me convert the dt.StartDate and dt.EndDate to varchar like the others so that I don't get this error. I tried googling for the syntax to convert datetime to varchar but can't seem to find it. Thanks...