I can't for the life of me figure out how this stored procedure works or what it is doing exactly, I know it works as is but I'm trying to limit some database calls which requires modifying this stored procedure.
CREATE PROCEDURE scriptassist.getQueue
@Status smallint = -1,
@GroupID uniqueidentifier = null,
@MACAddress varchar(200) = ''
AS
SET NOCOUNT ON
Print @GroupID
SELECT *
FROM [Queue]
WHERE
case @Status
When -1 Then
Case When ISNULL(Status,0) <> 1 Then 1 Else 0 End
Else
Case When ISNULL(Status,0) = @Status Then 1 Else 0 End
End =1
And
case When @GroupID IS NULL Then 1
Else
Case When GroupID = @GroupID Then 1 Else 0 End
End =1
And
case @MACAddress
When ''
Then 1
Else
Case When MACAddress = @MACAddress Then 1 Else 0 End
End =1
Order By DateEntered DESC
I know that somehow it is dynamically defining the Where Clause but I'm not sure what is getting done. Also if anyone knows of a tool that would let me see what is actually happening, thanks!