## 4 replies

Last post Aug 01, 2003 03:26 PM by yaheya

Participant

1635 Points

340 Posts

### Newbie help

Hi this maybe very elementary for some people. But I have this sql set nocount on declare @order_items int declare @counter int declare @order_num char(10) Select @order_items = 0 Select @counter = 0 select @order_items = Count(*) from order_detail_org While @counter < @order_items Begin Select @order_num = order_num from order_detail_org print @order_num Select @counter = @counter + 1 End it prints the same order_num...but what I want to do is print different order_num. I know this can be done using cursors. But I can't figure out how to use a cursor in the above scenario. Any help would be highly appreciated.
Yaheya Quazi
University of California, Merced

Contributor

2234 Points

459 Posts

### Re: Newbie help

What are you trying to accomplish, by rpinting all of these order numbers? What are you looking at as an end result...
-pjm

I never gave a damn about the meterman until I was the man who had to read the meter.

Participant

1635 Points

340 Posts

### Re: Newbie help

Well what I am trying to do is big. So I thought attack the problem in smaller pieces. But since you asked here is what I am trying to do - Notice the following two sets of sample data order_number Line Number Price 8908ABB23200 1 4 8908ABB23201 1 5 8908ABB23201 2 6 8908ABB23202 1 7 8908ABB23202 1 8 8908ABB23202 2 9 order_number Line Number Price 8908ABB23200 1 5 8908ABB23201 2 6 8908ABB23202 1 8 8908ABB23202 2 9 I want to create a sql that will produce the second group from the first. Here is the logic (or as much as I understand).. 1. If first 10 digit of order number matches and line number matches order number ending with 00, will be updated with the price information of order number 01, 02, 03 etc.... 2. if first 10 digit matches and line number does not exists then the new ordernumber (ending with 01...99) will be inserted. I have been struggling with this problem for weeks now. Please help
Yaheya Quazi
University of California, Merced

Contributor

2234 Points

459 Posts

### Re: Newbie help

I've read your requirements several times now, but I'm still fuzzy on what you are trying to do. Can you post a few examples, using the data sets you provided in your previous message?
-pjm

I never gave a damn about the meterman until I was the man who had to read the meter.

Participant

1635 Points

340 Posts