Friday 15 January 2016

Add Pre-Post fixed string in sql


Syntax of REPLICATE Function :

REPLICATE ( character_expression ,integer_expression )

character_expression is a string to repeat. 

integer_expression is number of times the character_expression to be repeated.

Return type of REPLICATE function is varchar data type.  


Example 1 : Use of REPLICATE function with select 

SELECT REPLICATE('Syntax-Example', 3) 


select (case when LEN([Columns Name])<5 then REPLICATE('0',5-LEN([Columns Name]))+[Columns Name] else Tally end)Tally from [Table Name] 

// Result :
//Before :  815
// After : 00815


Example 2 : Use of REPLICATE function with Update

update [Table Name]  set [Columns Name]=(case when LEN([Columns Name])<5 then REPLICATE('0',5-LEN([Columns Name]))+[Columns Name] else [Columns Name]end)




No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...