SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

seeker62
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.

bandi
Flowing Fount of Yak Knowledge

India
2202 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

seeker62
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
DECLARE tb_cur CURSOR
FOR
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
BEGIN
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
END
CLOSE tb_cur
DEALLOCATE tb_cur

Edited by - seeker62 on 04/12/2013 10:35:09
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.08 seconds. Powered By: Snitz Forums 2000