Reputation: 607
I have a nullable datetime2 column. The column contains the most recent login date. If the column is null, the user has not logged in.
I have a SSRS report that filters whether a user has logged in or not. If column is null, then user has not logged in. I have a parameter that takes multiple values(all,logged in, not logged in) that I pass to a stored proc. Currently I have set the values to Logged in = 1 and not logged in = 2.
My storedproc receives the value as @HasLoggedIn varchar(50).
How would I go about selecting either (all,logged in, not logged in) in sql.
Is there a better way to set this up in ssrs?
Upvotes: 0
Views: 103
Reputation: 3271
I'm a bit lost at passing the parameter, but basically I think you're looking for this:
DECLARE
@loginOption int = 0
SELECT
[UserID],
[Timestamp]
FROM [Logins]
WHERE
(CASE
WHEN @loginOption = 0 THEN 1 -- ALL
WHEN @loginOption = 1 AND [Timestamp] IS NOT NULL THEN 1 -- Logged in
WHEN @loginOption = 2 AND [Timestamp] IS NULL THEN 1 -- Not logged in
ELSE 0
END) = 1
And here is a Fiddle for it.
Upvotes: 2