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! )
⇒ Unicode String Literals in SQL Server Transact-SQL
⇐ Casting Strings to Wrong Code Pages in SQL Server Transact-SQL
2017-05-13, 4673🔥, 0💬
Popular Posts:
How To Insert New Line Characters into Strings in SQL Server Transact-SQL? If you want to break a st...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...
Where to find answers to frequently asked questions on Conditional Statements and Loops in SQL Serve...
How To Replace Given Values with NULL using NULLIF() in SQL Server Transact-SQL? Sometime you want t...
How To Count Rows with the COUNT(*) Function in SQL Server? If you want to count the number of rows,...