Link to home
Start Free TrialLog in
Avatar of teogos
teogosFlag for United States of America

asked on

INSERT INTO SQL QUERY FIELD

Data is coming from the SLQ database like this B1234DPRF . I want to modify this on a query
to show me like B-1234-DPRF      ,any ideas how to do this  so. after the first character insert a -   then after the fifth character insert another -
Avatar of Tony303
Tony303
Flag of New Zealand image

DECLARE @data as varchar(10)
SET @data = 'B1234DPRF'

SELECT @Data

SELECT left(@data,1) + '-' + Substring(@data,2,4) + '-' + SUBSTRING(@Data,6,4) AS Done

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of awking00
awking00
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
p.s. If always 4 characters after the last '-' then just substitute 4 for len(field).

You can also use left and right, I believe -
select left(field,4) +'-' substring(field(2,4) + '-' right(field,4)
Tony303, sorry I never saw your post before I submitted.
@awking.

Yeah, it is rare that I get a solution in first!!
Normally, while I am working the question out there are bigger brains on the job and get in before me!!!

Cheers now.
T :-)