Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

split column in sql query in a select statement and display as separate columns

Posted on 2011-05-06
4
Medium Priority
?
479 Views
Last Modified: 2012-05-11
I have a column in sql server database with columnname "LongDesc". I would like to split this column at a "." sign and display each of the results as a separate column.

something like""

select longdesc.split(',')(0), longdesc.split('.')(1) , longdesc.split(',')(2) from products

How can I do this and what is the syna=tax for doing this. Thanks

0
Comment
Question by:TrialUser
4 Comments
 
LVL 21

Accepted Solution

by:
Alpesh Patel earned 668 total points
ID: 35705685
0
 
LVL 7

Assisted Solution

by:waltersnowslinarnold
waltersnowslinarnold earned 664 total points
ID: 35705858
Plz use the following sample, it would help u..
SELECT SUBSTRING(LongDesc,1,CHARINDEX('.',LongDesc,1)-1),SUBSTRING(LongDesc,CHARINDEX('.',LongDesc,1)+1,LEN(LongDesc))

Open in new window

0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 668 total points
ID: 35705955
try
select LEFT(longdesc, charindex('.', longdesc)-1), RIGHT(longdesc, len(longdesc) -charindex('.', longdesc))

Open in new window

0
 
LVL 9

Expert Comment

by:anillucky31
ID: 35706627
Is there fixed number of . (dots) in columnname "LongDesc"?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

579 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