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

Posted on 2011-05-06
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

Question by:TrialUser
    LVL 21

    Accepted Solution

    LVL 7

    Assisted Solution

    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

    LVL 32

    Assisted Solution

    select LEFT(longdesc, charindex('.', longdesc)-1), RIGHT(longdesc, len(longdesc) -charindex('.', longdesc))

    Open in new window

    LVL 9

    Expert Comment

    Is there fixed number of . (dots) in columnname "LongDesc"?

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now