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

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...