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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help- Conditional Stored Procedure

Status
Not open for further replies.

JasSim

Programmer
Jul 24, 2000
12
0
0
US
I know this won't work but if someone can help put this together for me I would appreciate it. I have been banging my head against the wall on this one for a while now...

Trying to get data back from this stored procedure, I send it four variables but sometimes I would like to send it just three. The time I send it three I want the top query ran. I will send @Order = 0 if I don't want the Order variable used. Thanks!!

CREATE PROCEDURE getOrderlog
@Name1 Varchar(10),
@Proc1 Varchar(10),
@Order1 Varchar(10),
@Status1 Bit
AS
IF (@Order1 = "0") THEN
SELECT hospitalID, [Order], [Proc], OpenDate, OpenTime, roomMnemonic, roomName, numAttending, startDate, startTime, endDate, status
FROM Orderlog WHERE GivenTo = @Name1 and Closed = @Status1 and [Proc] = @Proc1;
ELSE
SELECT hospitalID, [Order], [Proc], OpenDate, OpenTime, roomMnemonic, roomName, numAttending, startDate, startTime, endDate, status
FROM Orderlog WHERE GivenTo = @Name1 and Closed = @Status1 and [Proc] = @Proc1 and [Order] = @Order1;
END IF;
 
The syntax for Sql Server stored procedure is


IF @Order1 = '0'
begin
your code
return
end

IF @Order1 = '1'
begin
your code
return
end

You can put a return in to jump out of your code and the stored procedure
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top