How to modify int ID to specify length?

Evan 40 Reputation points
2024-01-29T03:32:56.03+00:00

Suppose I have ID like 101,1923,10052... And I want all these ID in specified length which is 00101,01923,10052. Any solutions?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,436 questions
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 30,591 Reputation points
    2024-01-29T03:43:10.4466667+00:00

    Hi @Evan Try this:

    DECLARE @ID INT = 1923;
    SELECT FORMAT(@ID,'00000');
    

    Best regards, Cosmog Hong

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.