The Scenario for Inserting Leading Characters
How to Insert Leading Characters for the Above Scenario
--Create Development/Test Database CREATE DATABASE [DevDB] GO --Use Database USE [DevDB] GO --Create Table CREATE TABLE [dbo].[TestID]( [ID] [varchar](10) NULL ) ON [PRIMARY] GO --Populate Table With Data INSERT INTO dbo.TestID VALUES ('1'), ('12'), ('123'), ('1234'), ('12345'), ('123456'), ('1234567'), ('12345678'), ('123456789') GO --Test the Transformation Logic (number 10 is the ID column size) SELECT ID,RIGHT(('0000000000'+ID),10) as FilteredID FROM dbo.TestID GO --Execute the Transformation Logic (number 10 is the ID column size) UPDATE dbo.TestID SET ID=RIGHT(('0000000000000'+ID),10) GO
Learn essential SQL Server development tips! Enroll to our Online Course!
Check our online course titled “Essential SQL Server Development Tips for SQL Developers”
(special limited-time discount included in link).Sharpen your SQL Server database programming skills via a large set of tips on T-SQL and database development techniques. The course, among other, features over than 30 live demonstrations!
Recommended Online Courses:
- SQL Server 2022: What’s New – New and Enhanced Features
- Introduction to Azure Database for MySQL
- Working with Python on Windows and SQL Server Databases
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- A Guide on How to Start and Monetize a Successful Blog
- Data Management for Beginners – Main Principles
Check Also:
- SQL Server 2016 Top Features
- The set identity_insert Command in SQL Server
- The Import Flat File Wizard in SSMS v17.3
- Listing all Tables of a Linked Server’s Database
- How to Import and Export Unstructured Data in SQL Server – FileTables
- How to Import and Export Unstructured Data in SQL Server – FILESTREAM
- How to Import and Export Unstructured Data in SQL Server – The IMAGE Datatype
- Script that Returns SQL Server’s Version Name
- …more
Did you find this article useful and interesting? Feel free to leave your comment!
If you enjoy my SQL Server administration tips and articles, I have something special just for you. It is one of my eBooksand it is called “Administering SQL Server“. Check it out!
Subscribe to our newsletter and stay up to date with our latest articles on SQL Server and related technologies!
Check out our latest software releases! All our software tools have free trial versions to download.
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© SQLNetHub
Artemakis Artemiou, a distinguished Senior Database and Software Architect, brings over 20 years of expertise to the IT industry. A Certified Database, Cloud, and AI professional, he earned the Microsoft Data Platform MVP title for nine consecutive years (2009-2018). As the founder of SQLNetHub and GnoelixiAI Hub, Artemakis is dedicated to sharing his knowledge and democratizing education on various fields such as: Databases, Cloud, AI, and Software Development. His commitment to simplicity and knowledge sharing defines his impactful presence in the tech community.