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
Director, Admin. Comp. & Systems
University of California, Merced
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
Director, Admin. Comp. & Systems
University of California, Merced
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.
hi thanks for your help. I have figured out the update and insert statement. But now what I need is to run them both in a batch. I believe in order to do that I need cursors? I have no clue how I can do an update or insert depending on condition in a loop for
all the records in my database. Thanks.
Yaheya Quazi
Director, Admin. Comp. & Systems
University of California, Merced
yaheya
Participant
1635 Points
340 Posts
Newbie help
Jul 31, 2003 05:43 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced
pjmcb
Contributor
2234 Points
459 Posts
Re: Newbie help
Jul 31, 2003 06:48 PM|LINK
I never gave a damn about the meterman until I was the man who had to read the meter.
yaheya
Participant
1635 Points
340 Posts
Re: Newbie help
Jul 31, 2003 06:59 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced
pjmcb
Contributor
2234 Points
459 Posts
Re: Newbie help
Aug 01, 2003 02:51 AM|LINK
I never gave a damn about the meterman until I was the man who had to read the meter.
yaheya
Participant
1635 Points
340 Posts
Re: Newbie help
Aug 01, 2003 03:26 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced