all groups > sql server programming > november 2004 >
You're in the

sql server programming

group:

How to manipulate a text row into a table column? (Restatement of earlier problem)


How to manipulate a text row into a table column? (Restatement of earlier problem) mountain man
11/24/2004 10:13:02 PM
sql server programming: In an earlier post I made a fundamental inaccurate typo.
What I should have said is "initial column" (ie: col001).

Thank you very much to all the responses which were
helpful, and the article fantastic, as during the successive
imports of these (sometime large) text files, the order of
the rows invariably manifested shuffling.

To make a re-specification of the problem, using the row
numbers as indicated earlier in the article (thanks Steve)
http://groups.google.com/groups?q=4642ED84B33F
This article resolved this problem.

[quoted text, click to view]


Show the rows numbers for info only, the end
result table needs to look like the following:
[quoted text, click to view]

Once again, thanks for the assistance. Sorry about the original
and fundamental typo (Joe C. picked it up).

Any ideas gratefully received.


Pete Brown
Falls Creek
Oz
www.mountainman.com.au


Re: How to manipulate a text row into a table column? (Restatement of earlier problem) mountain man
11/24/2004 10:29:04 PM
Additionally, this earlier research may assist:

-- 1) Identify rows containing dept names
-- where r = identity row (replaced by the DOS insertion)
-- n = row number containing dept name
-- x = row number of next dept name (less one if helpful)

drop table deptrows
create table deptrows (
r int IDENTITY (1, 1) NOT NULL ,
n int null,
x int null)
go

-- 2) Write dept rows to deptrows

insert into deptrows (n)
select r
from x
where substring(col001,1,10)=' Department: '
order by 1
go

--select * from deptrows where
--select * from x

3) Read this table a second time and record in each row
the location of the immediately following dept-row ...

update deptrows
set deptrows.x = d2.n-1
--select d1.r "DR1", d2.n-1 "DN2" ----, d1.n "DN1", d2.n "DN2"

-- x.col001 --,x1.r,n, x1.col001
from deptrows
left join deptrows d2 on (deptrows.r=d2.r-1)


4) The problem remains to get to the DEPT rows thus
identified above into a table as a column ...



Re: How to manipulate a text row into a table column? (Restatement of earlier problem) mountain man
11/25/2004 8:25:23 AM
PROBLEM NOW RESOLVED.
Use of Cursor not required.
Thanks again, all.


Pete Brown
Falls Creek
Oz
www.mountainman.com.au



[quoted text, click to view]

AddThis Social Bookmark Button