473,781 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

T-SQL ASP While not rs.EOF

I am trying to write a stored procedure that utilizes something like a
while in ASP.

my select statement is like this.

s = select distinct(employ ee_id) from employee_table
rs.Open s

while not rs.EOF

then I want to use employee_id in about twenty different sql
statements. They are all different and they utilize multiple joins. I
use four - six different tables to find out a count in the sql
statement. Then I want to use the value from each of the sql
statements at the end to use in an insert statement. What would be the
best way.

insert into table (employee_id, value, value, etc..)

if not rs.EOF then
rs.MoveNext
end if
wend

Any help would be appreciated.
Jul 20 '05 #1
2 17128
brentster wrote:
I am trying to write a stored procedure that utilizes something like a
while in ASP.

my select statement is like this.

s = select distinct(employ ee_id) from employee_table
rs.Open s

while not rs.EOF

then I want to use employee_id in about twenty different sql
statements. They are all different and they utilize multiple joins. I
use four - six different tables to find out a count in the sql
statement. Then I want to use the value from each of the sql
statements at the end to use in an insert statement. What would be the
best way.

insert into table (employee_id, value, value, etc..)

if not rs.EOF then
rs.MoveNext
end if
wend

Any help would be appreciated.

Query Analyser has templates for using cursors, e.g.

--- Code Start ---
-- =============== =============== ===============
-- Declare and using an UPDATE cursor
-- =============== =============== ===============
DECLARE <@variable_1, sysname, @v1> <datatype_for_v ariable_1, sysname,
varchar(20)>,
<@variable_2, sysname, @v2> <datatype_for_v ariable_2, sysname, varchar(40)>

DECLARE <cursor_name, sysname, test_cursor> CURSOR
FOR SELECT <column_1, sysname, au_fname>, <column_2, sysname, au_lname>
FROM <table_name, sysname, pubs.dbo.author s>
FOR UPDATE of <column_1, sysname, au_fname>

DECLARE @count smallint
SELECT @count = 1

OPEN <cursor_name, sysname, test_cursor>
FETCH NEXT FROM <cursor_name, sysname, test_cursor> INTO <@variable_1,
sysname, @v1>, <@variable_2, sysname, @v2>

WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
-- PRINT 'add user-defined code here...'
-- eg
PRINT 'updating record of ' + @v1 + ' ' + @v2
UPDATE pubs.dbo.author s
SET au_fname = @v1 + '-' + CAST(@count AS varchar(4))
WHERE au_lname = @v2
END
FETCH NEXT FROM <cursor_name, sysname, test_cursor> INTO <@variable_1,
sysname, @v1>, <@variable_2, sysname, @v2>
SELECT @count = @count + 1
END

CLOSE <cursor_name, sysname, test_cursor>
DEALLOCATE <cursor_name, sysname, test_cursor>
GO
--- Code Ends ---

But consider trying to accomplish what you want to do using a batch SQL
statement as that'll be faster.

--
But why is the Rum gone?
Jul 20 '05 #2
Hi

A set based solution should be far more efficient that your cursor based
solution especially with larger amounts of data.

There is a large amount of documentation in Books online for cursors an
example:
mk:@MSITStore:C :\Program%20Fil es\Microsoft%20 SQL%20Server\80 \Tools\Books\ts q
lref.chm::/ts_de-dz_31yq.htm

John
"brentster" <br************ **@hotmail.com> wrote in message
news:d9******** *************** ***@posting.goo gle.com...
I am trying to write a stored procedure that utilizes something like a
while in ASP.

my select statement is like this.

s = select distinct(employ ee_id) from employee_table
rs.Open s

while not rs.EOF

then I want to use employee_id in about twenty different sql
statements. They are all different and they utilize multiple joins. I
use four - six different tables to find out a count in the sql
statement. Then I want to use the value from each of the sql
statements at the end to use in an insert statement. What would be the
best way.

insert into table (employee_id, value, value, etc..)

if not rs.EOF then
rs.MoveNext
end if
wend

Any help would be appreciated.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5481
by: Steve | last post by:
Hi; I'm brand spanking new to sqlserver ( nice so far ). I need to make a simple data change across a list of tables. Basically replace an old date with a new date. However, the people I am doing it for want a program that produces logging of what it does.
2
11946
by: Steve | last post by:
Hi; I have been writing a lot of short tsql scripts to fix a lot of tiny database issues. I was wondering if a could make an array of strings in tsql that I could process in a loop, something like array arrayListOfTablesToProcess = { "orders", "phone",
18
4622
by: mountain man | last post by:
Greetings to all database professionals and laymen, Let us make a bold assumption that we have developed a software tool for the SQL Server environment which simply acts as an interface between an end-user in an organization and the database, through the exclusive use of stored procedures which are authored by the organization or by software developers. All development work at the application software level may thereby be conducted...
2
18705
by: dynoweb | last post by:
I have several *.sql files with schema/data changes to be applied to our current database. Is there a way to create a TSQL script that could be run from the SQL Query Analyzer that would sequentially call the *.sql files? i.e. call schemaVersionCheck.sql call addFieldToLoanTable.sql call updateLoanTrigger.sql
1
1728
by: TOM GUGGER | last post by:
OMNI GROUP tgugger@aimexec.com T-SQL/ CONTRACT TO PERM/ ATLANTA
3
2542
by: David Lozzi | last post by:
Howdy, ISSUE 1: See issue 2 below. I have a distance calculator on my site which works great. However, the users need to sort by distance, which make sense. I'm not sure how to do it other than like this. With the returning query include the distance from origin. Here's my dilemma, I have the script working great in VB which provides the distance, but that is not sortable, but when I port it over to TSQL I get differing results. Here is the...
16
5093
by: David Lozzi | last post by:
Hello, I have some code that adds a new user. The new user has a checkboxlist of items which they can be associated with. I would like to send this list of items to TSQL along with the new user information. I would guess to combine the selected items like so: "6,4,8,19,2". Kind of do the following: INSERT into tblUser (fields) VALUES (data)
7
9386
by: Filips Benoit | last post by:
Dear all, Tables: COMPANY: COM_ID, COM_NAME, ..... PROPERTY: PRP_ID, PRP_NAME, PRP_DATATYPE_ID, PRP_DEFAULT_VALUE ( nvarchar) COMPANY_PROPERTY: CPROP_COM_ID, CPROP_PRP_ID, CPROP_VALUE (nvarchar) Use: Without adding new field the user can add new properties to the companies just by adding a new property in table PROPERTY and mapping the
8
1458
by: David Lozzi | last post by:
I'm fairly new to ASP.Net 2.0 SQLDatasource objects. It defaults using TSQL statments for the SELECT, INSERT, UPDATE, DELETE commands, which is great and it works. However, I've always been taught that all SQL work should be completed by the SQL server, therefore use stored procedures even for the simplest of select statements. Does this still hold true for sqldatasources? Should I use procs instead of the default tsql?? Thanks, ...
0
3155
by: DR | last post by:
Unable to start TSQL Debugging. Could not attach to SQL Server Process on 'srvname'. The RPC server is unavailable. I get this error when I try to run a SQL Server Project with a CLR stored Procedure in it. The target DB is SQL Server 2005 and im using VS 2005. I simply create a new SQL Server Project which creates a Test.sql, i then simply added a Stored Procedure to it called the default name StoredProcedure1.cs and put a break point...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10076
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.