I usually define size when declaring parameters in my SP, like :
@myParam nvarchar(size)
or when I casting or converting:
CAST(@myParam AS nvarchar(size))
Recently I’ve removed size from my CAST functions like:
CAST(@myParam AS nvarchar)
and I’m bit worried if that is going to come and bite me when least expected :-(, since I noticed truncation on nvarchar variables when using recursive CTE and casting nvarchar without specifying size.
Any comments?
If you omit the size, it defaults to 30. See this:
http://msdn.microsoft.com/en-us/library/ms186939.aspx
To see this in action, try executing the following statements:
Per @krul’s comment; 30 is the default length for CAST; however the default length for a data definition or variable declaration is 1.
NB: There’s also an STR function which converts numeric fields to strings, for which the default length is 10.