The SQL statement splits two columns of data into more than one

Source: Internet
Author: User

Original data

You want to split the two columns into:

SQL statements and ideas

Idea: Split column A and column B separately, with line numbers equal as conditional connections

SelectManagerid,manager from(SELECT row_number () over (ORDER by B.number) asOrderid,substring (Prjmanager,b.number,charindex (',', prjmanager+',', B.number)-B.number) as Manager from [dbo]. [Cm_contract] T1 INNER join master.dbo.spt_values B on b.number between1and Len (Prjmanager) and substring (','+prjmanager,b.number,1)=','   whereB.type='P') asT1 INNER JOIN (SELECT row_number () over (ORDER by Cntname) asOrderid,substring (Prjmanagerids,b.number,charindex (',', prjmanagerids+',', B.number)-B.number) as ManagerID from [dbo]. [Cm_contract] T1 INNER join master.dbo.spt_values B on b.number between1and Len (prjmanagerids) and substring (','+prjmanagerids,b.number,1)=','  whereB.type='P') asT2 on T1.orderid=t2.orderid

The SQL statement splits two columns of data into more than one

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.