DECLARE @var varchar(15) SET @var = 'This is a string that is longer than 15 characters.' IF object_id('tempdb..#testtable') IS NOT NULL DROP TABLE #testtable CREATE TABLE #testtable (pk int primary key identity ,field varchar(10) ) INSERT INTO #testtable (field) VALUES ('This is a string that is longer than 15 characters.') INSERT INTO #testtable (field) VALUES (@var) SELECT * FROM #testtableGives these results:
Server: Msg 8152, Level 16, State 9, Line 11 String or binary data would be truncated. The statement has been terminated. Server: Msg 8152, Level 16, State 9, Line 15 String or binary data would be truncated. The statement has been terminated. pk field ----------- ---------- (0 row(s) affected)BOb
>If the data to be stored is longer than number of characters allowed, >the data is truncated. For example, if a column is defined as char(10) >and the value “This is a really long character string” is stored into >the column, Microsoft® SQL Server™ truncates the character string >to “This is a”.>