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, 5932🔥, 0💬
Popular Posts:
How To Update Multiple Rows with One UPDATE Statement in SQL Server? If the WHERE clause in an UPDAT...
How To Convert a Unicode Strings to Non-Unicode Strings in SQL Server Transact-SQL? Since Unicode ch...
How To Install PHP on Windows in MySQL? The best way to download and install PHP on Windows systems ...
How to continue to the next iteration of a WHILE loop in SQL Server Transact-SQL? How to use CONTINU...
How to download and install Microsoft .NET Framework Version 2.0 in SQL Server? .NET Framework Versi...