NVARCHAR field getting truncated after increasing field length - sometimes

I have a very strange situation. I've increased the size of an NVARCHAR field from 8 to 9 in a database table. The format of the data that I enter will either be an 8 character field (123456-8) or a 9 character field (1234567-9). The '-' is critical.

It used to only accept the 8 character version, but after increasing the field size, if I try to insert the 9 character field version, it gets truncated after the '-', as though it's still only allowing 8 characters. But that only occurs when I include the '-' or other such characters like '#'. If I try to insert 1234567a9, it works. The following explains the outcomes:

Inserted Value -> Result in table

123456-8 -> 123456-8      *Correct 1234567-9 -> 1234567-     *Wrong 123456789 -> 123456789    *Correct 1234567#9 -> 1234567#     *Wrong 1234567a9 -> 1234567a9    *Correct


Why is it that characters such as '-' and '#' are truncating the value, but only if the string is 9 chars long?

I'm currently using a direct t-sql insert statement in SQLExpress. The field is a simple NVARCHAR(9) field.

Regards,

August 27th, 2015 11:08pm

Can you post the structure of the table including constraints and triggers? 
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 11:16pm

I've found the issue. I hadn't considered triggers until you raised the question. There was a trigger that was padding with zeros that was still only using a length of 8.

Thanks for your input

August 27th, 2015 11:39pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics