Created
June 19, 2015 16:45
-
-
Save DForshner/2f6c96857c647d6c5c8f to your computer and use it in GitHub Desktop.
Passing nullable parameter to stored procedure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE PROCEDURE [DB].[PassNullParameterToStoredProcedure] (@Started DateTime = NULL) | |
| AS | |
| BEGIN | |
| DECLARE @Data TABLE( Started DateTime NOT NULL) | |
| INSERT INTO @Data (Started) | |
| VALUES ('2015-01-01T00:00:00'), ('2015-01-02T00:00:00'), ('2015-01-03T00:00:00') | |
| SELECT * FROM @Data | |
| WHERE (@SessionStarted IS NULL OR Started = @SessionStarted) | |
| END | |
| GO | |
| EXEC [DB].[TestNullParameter] @SessionStarted = NULL -- Returns all | |
| EXEC [DB].[TestNullParameter] @SessionStarted = '2015-01-03T00:00:00' -- Returns one record |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment