[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

INSERT INTO SQL QUERY FIELD

Posted on 2013-12-02
5
Medium Priority
?
389 Views
Last Modified: 2013-12-03
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 -
0
Comment
Question by:teogos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Tony303
ID: 39691046
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

0
 
LVL 32

Accepted Solution

by:
awking00 earned 2000 total points
ID: 39691054
If always the second and seventh -
select substring(field,1,1) + '-' + substring(field,2,4) + '-' + substring(field,6,len(field))
0
 
LVL 32

Expert Comment

by:awking00
ID: 39691060
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)
0
 
LVL 32

Expert Comment

by:awking00
ID: 39691063
Tony303, sorry I never saw your post before I submitted.
0
 
LVL 12

Expert Comment

by:Tony303
ID: 39691100
@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 :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question