The example below uses the Left function to create a four character DataCode column from the first four characters of the DataDescription column of the FinancialData database table: SELECT DataID, DataDescription,Left(DataDescription, 4) AS DataCode FROM FinancialData ORDER BY DataID By contrast, the Right Transact SQL function truncates a string from the right side of that string. This example creates a DataCode column that is based on the final three characters of the DataDescription column: SELECT DataID, DataDescription, Right(DataDescription, 3) AS DataCode FROM FinancialData ORDER BY DataID To return part of a string, use the Substring function.
- SQL Server Documentation Tool Automatically document all of your SQL Server databases with this handy utility
No comments:
Post a Comment