Skip to content

Instantly share code, notes, and snippets.

@mattmc3
Created April 6, 2017 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmc3/ddbf0605ee19b9de58a0dcbc917d6dc6 to your computer and use it in GitHub Desktop.
Save mattmc3/ddbf0605ee19b9de58a0dcbc917d6dc6 to your computer and use it in GitHub Desktop.
MSSQL Find dreaded 'string or binary data will be truncated' error
select 'union all select ''' + isc.COLUMN_NAME + ''' as cn, max(len(' + isc.COLUMN_NAME + ')) as length, ' + convert(varchar(5), isc.CHARACTER_MAXIMUM_LENGTH) + ' as maxlen from {{table}} having max(len(' + isc.COLUMN_NAME + ')) > ' + convert(varchar(5), isc.CHARACTER_MAXIMUM_LENGTH) + ''
from INFORMATION_SCHEMA.COLUMNS isc
where isc.TABLE_NAME = '{{table}}'
and isc.CHARACTER_MAXIMUM_LENGTH is not null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment