To add hyphen sign or any other sign between a varchar value


If you want to add a  hyphen or any other sign in between a varchar column then you can you Stuff built in function of sql server.
syntax is

declare @test varchar(max) = '1234567890'
SELECT STUFF(STUFF(@test,4,0,'-'),8,0,'-')

the output of the following sql statement is "123-456-7890"

4,0 and 8,0 in stuff function means,
4 means insert hyphen at 4th position
0 means replace characters with  hyphen .In this case its 0 so it will not replace any character just insert  hyphen sign. Same as the case with 8,0

Comments

Popular posts from this blog

TSQL To Get All the Names of tables and Databases whose data have changed in last 24 Hours

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases

Apply paging in procedure