Collections:
CHAR(n) - Truncating/Padding Strings in SQL Server Transact-SQL
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL?
✍: FYIcenter.com
When the length of the input string does not match the storage size of the fixed length string data type CHAR(n). SQL Server will:
The tutorial exercise shows you good examples of truncating and padding fixed length character strings:
-- Length matches the data type size DECLARE @msg CHAR(36); SET @msg = 'Welcome to FYIcenter.com SQL Server!'; PRINT '('+@msg+')'; ---------------------------- (Welcome to FYIcenter.com SQL Server!) -- Length is bigger than the data type size - truncated DECLARE @msg CHAR(24); SET @msg = 'Welcome to FYIcenter.com SQL Server!'; PRINT '('+@msg+')'; ---------------------------- (Welcome to FYIcenter.com) -- Length is smaller than the data type size - padded DECLARE @msg CHAR(46); SET @msg = 'Welcome to FYIcenter.com SQL Server!'; PRINT '('+@msg+')'; ---------------------------- (Welcome to FYIcenter.com SQL Server! )
2017-05-13, 2110👍, 0💬
Popular Posts:
What Is a Constant or Literal in SQL Server Transact-SQL? A constant, or data literal, is a symbolic...
How do you know if SQL Server is running on your local system in SQL Server? After installing SQL Se...
How to execute statements under given conditions in SQL Server Transact-SQL? How to use IF ... ELSE ...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...
What Is a Constant or Literal in SQL Server Transact-SQL? A constant, or data literal, is a symbolic...