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

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(employee_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 17072
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(employee_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_variable_1, sysname,
varchar(20)>,
<@variable_2, sysname, @v2> <datatype_for_variable_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.authors>
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.authors
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%20Files\Microsoft%20SQL%2 0Server\80\Tools\Books\tsq
lref.chm::/ts_de-dz_31yq.htm

John
"brentster" <br**************@hotmail.com> wrote in message
news:d9**************************@posting.google.c om...
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(employee_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
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...
2
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...
18
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...
2
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...
1
by: TOM GUGGER | last post by:
OMNI GROUP tgugger@aimexec.com T-SQL/ CONTRACT TO PERM/ ATLANTA
3
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...
16
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...
7
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...
8
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...
0
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.