Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
seeker62
Starting Member
40 Posts |
Posted - 2013-04-12 : 09:34:34
|
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
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-12 : 09:45:05
|
Post the sample data in consumable format as well as expected output...explain the problem with your code? |
|
|
seeker62
Starting Member
40 Posts |
Posted - 2013-04-12 : 10:32:33
|
Here is more exact fetch relative (@move) is saying it is looking for ( or selectDECLARE @contract VARCHAR(15)DECLARE @move intDECLARE tb_cur CURSORFORSELECT contractnumFROM tableWHERE ProductType = 'co2'ORDER BY ContractNumOPEN tb_curFETCH NEXT FROM tb_cur INTO @contractset @move = (SELECT COUNT(*) FROM table WHERE ContractNum = @contract)WHILE @@fetch_status = 0BEGINset @move = (SELECT COUNT(*) FROM table WHERE ContractNum = @contract)UPDATE tableset 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 @contractENDCLOSE tb_curDEALLOCATE tb_cur |
|
|
|
|
|