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)
 Procedure to call 1 of 2 selects

Author  Topic 

ComputerMike
Starting Member

18 Posts

Posted - 2009-04-23 : 13:47:44
Hi,

I want to write a procedure that calls one of two select statements depending on a parameter. For example.......

CREATE PROCEDURE x
@Section int
AS
BEGIN

case @Section
when 1 then

Select Date, Customer, SalesAmount from Sales

When 2 then

Select date, vendor, PurchaseAmount, Tax from Purchases

end

END
GO

It seems it should be easy, but I don't have alot of experience with this.

Thanks,

Mike

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-23 : 13:53:29
CREATE PROCEDURE x
@Section int
AS
BEGIN

IF @Section = 1

Select Date, Customer, SalesAmount from Sales

if @section = 2

Select date, vendor, PurchaseAmount, Tax from Purchases

go



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -