This seems like a trivial syntax issue that I’m unaware of. I would like to define a function on the lines of trimming some data based on the allowed limit for column.
Here’s some sample code that works.
DECLARE @value nvarchar(max) = ' Test string abc '
DECLARE @length integer = 10
DECLARE @trimValue nvarchar(max) = @value
SELECT @trimValue = LTRIM(RTRIM(CAST(@value AS nvarchar(10))))
SELECT @trimValue
returns ‘Test str’
Now I want to pass in that casting length dynamically. How can I do this?
SELECT @trimValue = LTRIM(RTRIM(CAST(@value AS nvarchar(@length))))
you could use LEFT in this case since it is a string, otherwise you need to do it dynamically