1

Let's say I have nvarchar(300) column.

I append the text as follows:

update tablename set fieldname = fieldname + 'appended string'

How can I tell SQL Server to automatically trim the text from beginning to ensure it never exceeds the maximum column length?

SharpAffair
  • 5,558
  • 13
  • 78
  • 158
  • 1
    If you're dealing with **Unicode** string literals in SQL Server (and `nvarchar` is Unicode) - you should always use the `N'...'` notation - e.g. `update tablename set fieldname = fieldname + N'appended string'` to make it clear that your string literal is Unicode ... – marc_s Feb 24 '13 at 21:15

1 Answers1

1

You could use the RIGHT function for that:

update tablename set fieldname = RIGHT(fieldname + N'appended string', 300)
Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137