Skip to content
Advertisement

insert char into string at multiple positions sql

how would i like to convert accounting GL number

99999999999999999

to

999-99999-99-9999.999

in a query to MSSQL server 2005

i dont need to update the data, just have the STRING be converted on query.

Table: GLM_MASTER__ACOUNT Field: Account

thanks.

Advertisement

Answer

One more way using STUFF()

DECLARE @a varchar(64)
SET @a = '99999999999999999'
SELECT  STUFF(STUFF(STUFF(STUFF(@a, 4, 0, '-'), 10, 0, '-'), 13, 0, '-'), 18, 0, '.')
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement