Created
April 6, 2017 01:07
-
-
Save mattmc3/ddbf0605ee19b9de58a0dcbc917d6dc6 to your computer and use it in GitHub Desktop.
MSSQL Find dreaded 'string or binary data will be truncated' error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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