This question already has answers here:
Most efficient T-SQL way to pad a varchar on the left to a certain length? (20 answers)
Closed 4 days ago.
i want to Form a String of length 20 character with preceding zero as per rule as given below.
my table looks like:-
The maximum number of 0 preceed in these five field are for CLASS: 4 VENDOR : 5 STYLE : 4 COLOR: 3 SIZE: 4
Output Table looks like:-
Can we do this with sql query. Please help.
The Output should looks like:-
2条答案
按热度按时间jchrr9hc1#
If you are using SQL Server 2012 and later versions, you can also make use of the
CONCAT()
functionvd8tlhqk2#
The simplest way is to use
format()
functionIf you want to show 00000 instead of nulls then :
So the String of length 20 characters with preceding zero could be :
Demo here