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 2005 Forums
 Transact-SQL (2005)
 Join results from stored proc

Author  Topic 

omeganet
Starting Member

1 Post

Posted - 2008-10-10 : 12:56:22
Hello everybody. I have the following problem.

I have a stored procedure, called sp_GetEventInfo(EventID int). It returns a result with two columns and one row: EventId, EventTitle.

I have to create another stored procedure, which takes top 5 rows from two tables and for each row I have to get its EventTitle using the stored procedure. I should return result like this: EventId, EventTitle, StartDate, EndDate. StartDate and EndDate are from the two tables, and the EventTitle is from the stored procedure. How can I do this? I the cursor the best solution?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-10 : 13:01:49
it better to create a user defined function rather than current procedure with same logic to return eventid and date. then you could simply use

SELECT f.eventid,f.eventdate,{t1/t2}.startdate,{t1/t2}enddate
from table1 t1
join table2 t2
on columns
cross apply dbo.yourcreatedfn(passingfield)f
Go to Top of Page
   

- Advertisement -