Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Analyser and Recrodset

Status
Not open for further replies.

DennisTheMenace

IS-IT--Management
Joined
Jul 25, 2001
Messages
113
Location
US
Can I use Query Analyser from Enterprise Manager to
- execute a stored procedure
- have those records in a recordset
While Not rs.eof
- execute another SP to delete related
in another table based on recordset("idrecord")
- execute a third SP to delete the original record
from the the recordset("idrecord")
Movenext
loop

I am new to scripts. When I execute the one line script:
execute sp_RetrieveEmptyRecords
It simply displays them in the results window and not a recordset that I can scroll thru. A very simple sample would GREATLY be appreciated.

Thanks! =====================
Dennis B

Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
The deletion can be done in a single stored procedure without the need for a recordset to loop through. In the second part though, are you wanting the stored procedure to display the records to be deleted, before it deletes them?
 
I understand the single SP to delete...

But my first delema is retrieving all of the "empty" records, deleting the associated record in the 2nd table (if found) and then delete the main empty record.

-Dennis =====================
Dennis B

Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
A record was created but all of the fields are null...

How bout we just say:
1) I want to retrieve all records in the table SOUP that have chrSoupType="Chunky"
2) Delete all records in the table BOWLS that have idSOUP
3) Delete that idSOUP from the table SOUP
4) Move to next record and start again

(lunch time... can you tell?) :o) =====================
Dennis B

Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
create procedure sp_LunchTime (@SoupName varchar(25))
as
select * from SOUP where chrSoupType = @SoupName
delete BOWLS where idSOUP = (select idSOUP from SOUP where chrSoupType = @SoupName)
delete SOUP where idSOUP = (select idSOUP from SOUP where chrSoupType = @SoupName)

:-Q
 
Thank you!

Will there be a problem if I encounter a BOWLS where there is no idSoup that matches?
>delete BOWLS where idSOUP = _
>(select idSOUP from SOUP where chrSoupType = @SoupName)


=====================
Dennis B

Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 
Ran fine... found 27,000 records, but then produced this error:

Server: Msg 512, Level 16, State 1, Procedure sp_DeleteLastMonthSoupBowls, Line 12
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated. =====================
Dennis B

Remember - YOU ARE UNIQUE!!!... Just like EVERYONE ELSE! ;o)
 

Try this.

select * from SOUP where chrSoupType = @SoupName

delete BOWLS
where idSOUP IN
(select idSOUP from SOUP
where chrSoupType = @SoupName)

delete SOUP where chrSoupType = @SoupName Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top