Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Returning multiple SELECT Statements

Author  Topic 

huge
Starting Member

31 Posts

Posted - 2003-03-17 : 12:55:42
Hey guys I have been looking all over for a cure for this and I dont want to have to use seperate calls to different Sprocs, I wanna do this all in one shot. And UNION will not work as the data is different datatypes.

Ok I have a stored procedure that has 3 seperate statements depending on where and/or if there is data. I will paste the whole sproc if you want but I need to return
1) a flag (either 1, 2, 3)
2) depends on if data is there, if it is then I need Description

here is the code

quote:

--SEARCH RESULT FOR SEARCH METHOD 1, GIVEN JOB# AND STN#
CREATE PROCEDURE dbo.validate_JobStn
@job nvarchar(5) = null ,
@stn nvarchar(3) = null
AS

declare @flag smallint

IF EXISTS --If the record is to be updated then pull all the needed informaiton from the database with that jnum and snum
(SELECT * FROM STN WHERE Job_Num = @job AND STN_Num = @Stn)
BEGIN
SET @flag = 1

SELECT S.*, I.img_name, I.imageid
FROM STN S
INNER JOIN [Image] I ON I.STN_id = S.STN_key
WHERE S.Job_Num = @job
AND S.STN_Num = @Stn

SELECT M.CAT_id
FROM Merge_ImageCategory M
INNER JOIN STN S ON M.STN_id = S.STN_key
WHERE S.Job_Num = @job
AND S.STN_Num = @Stn

SELECT FLAG = @flag
END
ELSE
BEGIN --SINCE the record is not in Image Quotes then put it in STN
INSERT INTO STN (Job_Num, STN_Num)
VALUES (@job, @stn)

SELECT STN_key
FROM STN
WHERE Job_Num = @job
AND STN_num = @stn

IF EXISTS (SELECT * FROM TimeCard..STN_Numbers WHERE Job_Number = @job AND STN_Number = @Stn)
BEGIN
SET @flag = 2 -- Station is not in our database but exists in the Timecard database, if this is the case pull the Description
SELECT Stn_Description as [Description]
FROM TimeCard..STN_Numbers
WHERE Job_Number = @job
AND STN_Number = @Stn

SELECT FLAG = @flag
END
ELSE
BEGIN
SET @flag = 3
SELECT FLAG = @flag
END
END
GO



Now this returns 3 seperate tables, how (in VB preferably) can I access the rows of each table with one recordset?? I have tried a bunch of stuff to no avail. PLease help

THanks in advance
HuGE

nr
SQLTeam MVY

12543 Posts

Posted - 2003-03-17 : 13:09:25
a union will work as you can create the recorset columns to include those from all tables and use null for the columns from the other two tables in the union.
You could also return three recordsets and access them from the recordset collection in VB - see nextrecordset.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SqlStar
Posting Yak Master

121 Posts

Posted - 2003-03-18 : 08:22:58
Hi

If u r using ADO 2.6, u can use this "NextRecordset" method.





":-) IT Knowledge is power :-)"
Go to Top of Page
   

- Advertisement -