sql server - How to separate the string value and create temp to store separate string in temp table -


I am using SQL Server 2005.

I have created a table with the column ID and courses . The records are as follows:

ID & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Course

1. & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Java, ASP.NET, C #
2. & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Java;
3. & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Java, C #
4. & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Html

course column type is varchar and values ​​are different from commas. I want to separate every word and store it in another or temporarily. Table

The output should be like this:

ID & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Course
1. & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Java
2. & nbsp; & Nbsp; & Nbsp; & Nbsp; ASP.NET
3. & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; C #
4. & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Html

The ID is not important here.

Thank you.

see

this is the best source:

Create a partition function, and use it like this:

 Select  * Join your table Y inner dbo.splitFunction (@Parameter) s on y.ID = S.Value  

For this method to work, you need to setup a time table:

  SELECT TOP 10000 IDENTITY (int, 1,1) AS numbers from sys.objects join s1 cross sys.objects s2 change number add number PK_ Points Primary Key Cluster (number)  

Once the table table is set, create this function:

<, create function [dbo] [FN_ListToTable] (@SplitOn four (1) --REQUIRED, to split @List string on the character @list varchar (8000)> - necessary, to divide the list separately) return form as return In (----------------- Single QUERY-- these blank lines will not return ----------- ----- SELECT ListValue FROM (SELECT LTRIM (RTRIM (SUBSTRING (list2, number + 1, CHARINDEX (@SplitOn , List2, Number + 1) -Member-1))) List Price (SELECT @SplitOn + @list + @SplitOn AS List 2) AT DT Inner Number Join OnN.N. Number & lt; LAN (DT List 2) Where subbitinating (List 2, Number, 1) = @ Spliton) DT 2 Where the list price is zero and the list price is not! = ''); Now you can easily split a CSV string into a table and add it to: .fn_ListToTable (',', '' 1,2,3 ,,, 4,5,6777 ,,,,)

Output:

  ListValue -------- --------------- 1 2 3 4 5 6777 (6 lines (affected))  

To make the work you need, Use the cross application:

  DECLARE @tbl_A table (Rowwidt Entry, Roewe Curvar (500)) DECLARE @tbl_b Table (Rowlit Int Identification, Roewe Curvar (500)) @ TBLA_A Value ( 1, in Java Insert into values ​​(2, 'Java') @tbl_A values ​​(3, 'Java, C #) @tbl_A values ​​in the values ​​(4, Log in), ASP.Net, C #') @tbl_A values ​​(4, 'Html') @tbl_b (RowValue) @tbl_A Apply separate st.ListValue from the cross Select dbo.FN_ListToTable (',', RowValue) as st command, select st.ListValue by * command @tbl_b from ROWID < / Code> 

By Output:

  Rohid Roview ----------- -------------- 1 ASP.NET 2C # 3 HTML 4 Java (4 lines (affected))  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -