Add optional parameter to a store procedure


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi,

I have the following store procedure in the DDT

@pEmployeePK INT,

@pServiceCallsScheduleDate DATETIME

AS

SELECT DISTINCT dbo.ServiceCalls.*

FROM dbo.ServiceCalls

RIGHT OUTER JOIN dbo.SC_Appliances

ON (dbo.ServiceCalls.PK_ServiceCalls = dbo.SC_Appliances.FK_ServiceCalls)

WHERE (dbo.ServiceCalls.Status NOT IN (2,3))

AND (dbo.SC_Appliances.IncludeInSCRoute = 1)

AND (dbo.SC_Appliances.FK_Employees = @pEmployeePK)

AND (dbo.SC_Appliances.ServicedDate = @pServiceCallsScheduleDate);

SELECT DISTINCT dbo.SC_Appliances.*

FROM dbo.SC_Appliances

RIGHT OUTER JOIN dbo.ServiceCalls

ON (dbo.SC_Appliances.FK_ServiceCalls = dbo.ServiceCalls.PK_ServiceCalls)

WHERE (dbo.ServiceCalls.Status NOT IN (2,3))

AND (dbo.SC_Appliances.IncludeInSCRoute = 1)

AND (dbo.SC_Appliances.FK_Employees = @pEmployeePK)

AND (dbo.SC_Appliances.ServicedDate = @pServiceCallsScheduleDate);

The parameter @pEmployeePK should be optional, which mean, that I can either pass a value or pass 0, in VB code I would simple do something like this:

If tEmployeePK > 0 Then

     cmd.Parameters.AddWithValue("@pEmployeePK", tEmployeePK).SqlDbType = SqlDbType.BigInt

End If

How would I code the same condition in T-SQL for the store procedure?

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search