Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 while fetch
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

40 Posts

Posted - 04/12/2013 :  09:34:34  Show Profile  Reply with Quote
I have a table that has contracts with several shipping orders assinged to that contract. I am updateing that table by setting the contract volume of the contract. Once I populate that i want to fetch the next contract that is different than the one i was just on which would mean that i would move through several records in table before i populated the next contract volume. This would be done in a loop until i reached eof. Does fetch next have an option to say fetch next 10 as an example? This update will be in an sp and will be ran hourly.

Flowing Fount of Yak Knowledge

2242 Posts

Posted - 04/12/2013 :  09:45:05  Show Profile  Reply with Quote
Post the sample data in consumable format as well as expected output...

explain the problem with your code?
Go to Top of Page

Starting Member

40 Posts

Posted - 04/12/2013 :  10:32:33  Show Profile  Reply with Quote
Here is more exact fetch relative (@move) is saying it is looking for ( or select

DECLARE @contract VARCHAR(15)
DECLARE @move int
SELECT contractnum
FROM table
WHERE ProductType = 'co2'
ORDER BY ContractNum
OPEN tb_cur
FETCH NEXT FROM tb_cur INTO @contract
set @move = (SELECT COUNT(*) FROM table
WHERE ContractNum = @contract)

WHILE @@fetch_status = 0
set @move = (SELECT COUNT(*) FROM table
WHERE ContractNum = @contract)
UPDATE table
set contractedvolume = (SELECT TOP 1 quantity
FROM table idq
INNER JOIN table ch ON ch.ContractID = idq.RecordID
WHERE ch.ContractNum = @contract)
FETCH RELATIVE(@move) FROM tb_cur INTO @contract
CLOSE tb_cur

Edited by - seeker62 on 04/12/2013 10:35:09
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000