SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 split function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

folumike
Starting Member

14 Posts

Posted - 05/21/2012 :  18:35:07  Show Profile  Reply with Quote
How do i split the table below
USING MSSQL 2000

Before

Date | Warehouse | BegBalance
Apr 2 2012 W1,W2,W3 | 20/40/10
Apr 4 2012 | W1,W2,W3 | 10/30/20


AFTER


Date | Warehouse | BegBalance
Apr 2 2012 | W1 | 20
Apr 2 2012 | W2 | 40
Apr 2 2012 | W3 | 10
Apr 4 2012 | W1 | 10
Apr 4 2012 | W2 | 30
Apr 4 2012 | W3 | 20

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 05/21/2012 :  18:44:31  Show Profile  Reply with Quote
will it be always 3 Warehouses max?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

folumike
Starting Member

14 Posts

Posted - 05/21/2012 :  18:53:43  Show Profile  Reply with Quote
No, it could be more than 3 warehouses

quote:
Originally posted by visakh16

will it be always 3 Warehouses max?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 05/21/2012 :  19:09:58  Show Profile  Reply with Quote
see

http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

folumike
Starting Member

14 Posts

Posted - 05/21/2012 :  19:22:14  Show Profile  Reply with Quote
Thanks so much.
But how about if the warehouses are 3 (max)

quote:
Originally posted by visakh16

see

http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 05/21/2012 :  19:27:54  Show Profile  Reply with Quote
hmm... if its only up to maximum of 4 rows you can use

SELECT Date,PARSENAME(REPLACE(Warehouse,',','.'),1) AS WareHouse,PARSENAME(REPLACE(BegBalance,'/','.'),1) AS BegBalance
FROM table

UNION ALL

SELECT Date,PARSENAME(REPLACE(Warehouse,',','.'),2),PARSENAME(REPLACE(BegBalance,'/','.'),2)
FROM table
WHERE PARSENAME(REPLACE(Warehouse,',','.'),2) IS NOT NULL
OR PARSENAME(REPLACE(BegBalance,'/','.'),2) IS NOT NULL

UNION ALL

SELECT Date,PARSENAME(REPLACE(Warehouse,',','.'),3),PARSENAME(REPLACE(BegBalance,'/','.'),3)
FROM table
WHERE PARSENAME(REPLACE(Warehouse,',','.'),3) IS NOT NULL
OR PARSENAME(REPLACE(BegBalance,'/','.'),3) IS NOT NULL


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000