I have several stored procedures that take a date/time input, one of which takes a date only in the form of a nvarchar
because it utilizes dynamic SQL. When I try to cast the variable going into the stored procedure, I get an error. This doesn't make much sense to me.
I know I can work around it by creating a second set of nvarchar
variables or casting within the stored procedure, but I'd like some insight on why I can't just cast the variable in-line.
Example. *TOP is a Select statement telling me my NVARCHAR DATE kicks out just fine.
MID is where SSMS is throwing the error, BOTTOM is where SSMS thinks it's just fine.*
nvarchar
without length, and never mind why is this a string, why is itnvarchar
instead ofvarchar
?select
, not aset
3. OK, that explains it. 4. Will do. 5. Because the sproc uses dynamic SQL, as stated in the question.sp_executesql
, not concatenating and double-single-quoting some date that has been changed to a string.