473,439 Members | 1,926 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,439 software developers and data experts.

How to set while statement equal to the end of the record file

maxamis4
295 Expert 100+
I am migrating from MS Access to MS Sql. I know access uses the eof which means end of record file. How do i create a while statement that I can set equal to the end of the record file.

I have a list of records 30,000 and I need to loop through them one by one.
May 4 '10 #1
3 2438
ck9663
2,878 Expert 2GB
Although it is not advisable and I don't know why you need it to read one record at a time, but if that's your requirement, you're going to need to use CURSOR.

There might also be a set-based way of doing it. Post what you need to do or your sample code so that we can give a more efficient suggestion.

Good Luck!!!

~~ CK
May 5 '10 #2
maxamis4
295 Expert 100+
Thanks for your response My requirements are as follows:

The purpose of my stored procedure is to change records in a resolved status to closed. By making this change I will have to update multiple tables that are impacted by the change.


My thinking behind it was to identify all the records that are in a resolved status. From there get the unique id that is used by the other two child tables and update/insert them based on that unique id.

Based on this I was thinking of using a while statement as I cycle through the records to update the two child tables and the main table.

My stored procedure is pretty general because I have just started coding and I have only declared my variables.

I was thinking of using my counter on my while statement as the total number of records that returned from the parent table and the total number of tickets that were resolved.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SET @COUNTER = (SELECT COUNT(dbo.call_req.status) AS Stat_Count FROM bo.call_req INNER JOIN dbo.ca_contact ON dbo.call_req.group_id = dbo.ca_contact.contact_uuid WHERE(SUBSTRING(dbo.ca_contact.last_name, 1, 3) = 'GSA') AND (dbo.call_req.status = N're'))
  3.  
  4.  
.

As I mentioned I have a strong MS Access background but if there is a better method of doing it I welcome it. If you have links or examples that would be very helpful.

thanks for the help
May 6 '10 #3
ck9663
2,878 Expert 2GB
Here are some steps you could follow.

1. Enclosed the entire process in TRANSACTION. This should help you rollback the data just in case something happen.
2. Use TRY..CATCH. Place the rollback in CATCH part.
3. Use the OUTPUT CLAUSE. To identify what records were updated. Something like this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE YOURTABLE 
  2. set STATUS = 'CLOSED' 
  3. OUTPUT INTO #temptable
  4. FROM YOURTABLE
  5. where STATUS = 'RESOLVED' 
  6.  
Your #temptable should have the same structure as the table you're updating.

4. Update all the other table using the #temptable. Something like this:
Expand|Select|Wrap|Line Numbers
  1. Update YourOtherTable
  2. set whateverfields = towhatevervalue
  3. from YourOtherTable
  4. inner join #temptable t on YourOtherTable.UniqueId = t.UniqueId
  5.  
5. Commit your transaction


Happy Coding!!!

~~ CK
May 6 '10 #4

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

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.