Help with Stored Procedure

IT_is_spatial

New member
Joined
Jun 10, 2005
Messages
3
Programming Experience
Beginner
I'm brand new to SQL so I was hoping for a little help. I'm sure this is pretty easy.

I've got a table with 3 columns.

ZIP | LOWSEG | HIGHSEG
----------------------------
72015| 01 | 99 |

What I need is to loop through each record and insert a new record for each value between the LOWSEG and HIGHSEG. So my end table will look something like

ZIP | LOWSEG | HIGHSEG
--------------------------------
72015 | 01 | 99
--------------------------------
72015 | 02 | 99
---------------------------------
72015 | 03 | 99
---------------------------------
ETC..........................


I've got a vbs script that does what I want. But I'm wanting to move it to a stored procedure.

Any help would be great Thanks
 
you mean you want to insert new field (column) in each record , simply you alter the table structure to add the new column
VB.NET:
alter tabel TableName 
add NewColumn int Not Null
change the table name and the datatype of the new column and the nullability
 
No, I'm wanting to insert a new record in the table for each value that falls between the LOWSEG and HIGHSEG. Check out the make shift result table above.
 
Get the current values and add new rows in a loop.
VB.NET:
[color=Blue]Dim[/color] zip, lowSeg, highSeg [color=Blue]As Integer[/color] [color=Green]'Retrieve these values from the existing data.[/color]
[color=Blue] Dim[/color] newRow [color=Blue]As[/color] DataRow

[color=Blue] For[/color] i [color=Blue]As Integer[/color] = lowSeg + 1 [color=Blue]To[/color] highSeg - 1 [color=Blue]Step[/color] 1
	newRow = table.NewRow()
	newRow("ZIP") = zip
	newRow("LOWSEG") = i
	newRow("HIGHSEG") = highSeg
	table.Rows.Add(newRow)
[color=Blue] Next[/color]
Do you know how to retireve the existing data from the database and then commit the new data?
 
Thanks for the reply, I've already got vb script working that will do what I'm looking for. I am wanting to move it to SQL within a stored procedure so I can automate it with our other procedures.
 
Back
Top