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
 Old Forums
 CLOSED - General SQL Server
 Stored procedure join multiple select statements - New post

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-06-29 : 08:06:30
Vishwa writes "I apologize for my previous post which was incorrect. Here is the new one.

I need to concatenate results of two select statements. I cannot use UNION as they produce different results. So I created two temporary tables to hold the results of each select statement. Now I want to concatenate the results from two temporary tables into a new table and do a select on it to get final result. The concatenated result can then be displayed in a asp.net datagrid. How can I do this? I am novice to stored procedure - this is my second day!

Here is the procedure:

CREATE PROCEDURE dbo.ResourceDetailsGivenEventId_sp
(
@eid varchar(50)

)
AS
declare @type varchar(50)
declare @srcid varchar(50)
declare @resid varchar(50)
declare @des varchar(50)
declare @loc varchar(50)
declare @resgrpid varchar(50)
declare @ch varchar(100)
declare @sla integer
declare @service varchar(100)
declare @servicedes varchar(100)


Declare @tbl1 table (RowId int identity(1,1), ResourceId varchar(100), ResouceDescription varchar(100), ResourceLocation varchar(100), ResourceDetails varchar(100))
Declare @tbl2 table (RowId int identity(1,1), AppType varchar(100), AppName varchar(100), AppScope varchar(100), AppLicenced varchar(100), AppDetails varchar(100))

Declare @tbl3 table (RowId int identity(1,1), ResourceId varchar(100), ResouceDescription varchar(100), ResourceLocation varchar(100), ResourceDetails varchar(100),AppType varchar(100), AppName varchar(100), AppScope varchar(100), AppLicenced varchar(100), AppDetails varchar(100))

Select @sla=slaid, @srcid=EventSourceId, @type=EventSourceGeneric from dbo.tEvent where EventId=@eid
print @sla
print @srcid
print @type
Select @service=ServiceId, @ch=ChannelId from dbo.tSLA where SLAID=@sla
print @type

insert @tbl1
Select ResourceID, ResourceDescription, ResourceLocation, ResourceDetails from dbo.tResource where ResourceIP=@srcid
select * from @tbl1

insert @tbl2
Select tChannel.ChannelDescription, tService.Description, tService.ServiceContact from dbo.tChannel LEFT JOIN dbo.tService ON tChannel.ServiceId=tService.Serviceid where tChannel.ChannelId=@ch
select * from @tbl2



GO"

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-29 : 14:28:38
I don't see anything that is in common between the two tables (@tbl1 and @tbl2) so I don't see how you are going to be able to join them. What is the relationship between these two tables?

Tara
Go to Top of Page
   

- Advertisement -