Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting data, cursor set or stored procedure?

Status
Not open for further replies.

Zargo

Programmer
Mar 21, 2005
109
Hi all,

I have a table with 3 columns
TableA
ColumnA ColumnFrom ColumnTo
566677 A1 A6
341334 TEST TEST
234333 000023 000150

I must put this information into another table with all values between ColumnFrom and ColumnTo

TableB
ColumnA ColumnB
566677 A1
566677 A2
566677 A3
566677 A4
566677 A5
566677 A6
341334 TEST
234333 000023
234333 000024
....and so on..


How can i realize this? A big star for the golden answer.

Thanks a lot...





 
Sorry i forget to add this. I have another table with the actual values:

Table3

columnA
A1
A7
A8

So i only will get these values in tableB:

TableB
ColumnA ColumnB
566677 A1
566677 A7
566677 A8
and so on...
 
I'd suggest that you look into how to design a database.. Until then this query will select the data. However, You will probalby need to tweak it depending on your actual data as string comparison's with different "types" of data are fickle at best.

Code:
DECLARE @TableA TABLE(ColumnA INT, ColumnFrom VARCHAR(10), ColumnTo VARCHAR(10))

INSERT @TableA
SELECT 566677, 'A1', 'A6' UNION ALL
SELECT 341334, 'TEST', 'TEST' UNION ALL
SELECT 234333, '000023', '000150'

DECLARE @Table3 TABLE (columnA varchar(10))

INSERT @Table3
SELECT 'A1' UNION ALL
SELECT 'A7' UNION ALL
SELECT 'A8' UNION ALL
SELECT 'TEST' UNION ALL
SELECT '000024' UNION ALL
SELECT '000010' 


SELECT a.ColumnA,
	b.ColumnA
FROM
	@TableA a
CROSS JOIN
@Table3 b
WHERE
(
	a.ColumnFrom <= b.ColumnA
	AND a.ColumnTo >= b.ColumnA
)

-Ryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top