This is the code I’ve managed to research. The whole table is imported from SQL, as NOT NULL. I get an error message when running it, “Invalid length parameter passed to the RIGHT function”. It only seems to give this error message, if a field has blank entries in it.
How do I change this script to only run if the field is not null?
UPDATE [Majestic].[dbo].Fields_custom
SET maxlength=left(right(cast(maxlength as nVarChar),LEN(cast(maxlength as nVarChar))-1),LEN(cast(maxlength as nVarChar))-2)
WHERE maxlength IS NOT NULL
Just add a condition that your field must have quotes at the beginning and end: