473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Update and select next value from a list

I am trying to write a stored procedure add a piece of data from table2 into another table1.

I thought the query was going to be easy, but I was misteken. All I am trying to achieve is: for each row in table 1 that meets specific criteria have 'the next value' from table 2 added to it. There are no columns I can use to link the tables.

I have written this code but it does not work properly if there are more then one row that needs updating.
Expand|Select|Wrap|Line Numbers
  1. DECLARE @oacseqn varchar(10)
  2. declare @oac varchar(15)
  3.  
  4. --find the max sequence number (so we can use the next row)
  5. select @oacseqn = max(seqn) from Sciquest_oac where used = 1 
  6.  
  7. --get next oac from Sciquest_oac 
  8. select @oac = oac from sciquest_oac where seqn = @oacseqn+1
  9.  
  10. update [Name_Sub_Record] set 
  11.  OAC_number = @oac
  12. from [Name_Sub_Record] s
  13. where s.via_SQ = 'false' and 
  14. s.publ_product like 'abcd_%' 
  15.  
  16. update Sciquest_oac set used = 'true' where seqn = @oacseqn+1
  17.  
does anyone have any thoughts about how I could go about doing this?
Jan 24 '08 #1
1 2313
Delerna
1,134 Expert 1GB
are there any fields in [Name_Sub_Record] from which you can generate a row number which can be added to your variable when doing the update

Or

are you using SQLServer 2005 which has a Row number function


as a last resort
you could try a cursor, but only do that if you can't find any other way.
Cursors are slow and not recommended, but they are sometimes the only way.
Check your helpfiles if you haven't used them before
Jan 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
2
by: Colin Steadman | last post by:
Part No Description Quantity 45643 Random part 10 45678 Another Random part 7 98944 And another 1 <submit button> ...
1
by: John Doe | last post by:
I have a PHP page that generates a list box with several options in it. I would like to have a "view" link next to the list box. When the user changes the contents of the list box, I would like...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
15
by: graham | last post by:
Hi all, <bitching and moaning section> I am asking for any help I can get here... I am at the end of my tether... I don;t consider myself a genius in any way whatsoever, but I do believe I have...
6
by: EiEiO | last post by:
Hi All... I have an unbound form. The form includes: A ComboBox (from table Callers) "cmbTMCode " A ListBox MultiSelect=Extended, (from table Leads) "lstSelect" A CommandButton "btnAssign" ...
5
by: P.J.M. Beker | last post by:
Hi there, I'm currently writing a program in which I use the FileMonitor to monitor a folder in which I store downloaded images. I know that I can't add much coding in the filemonitor's event in...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.