I have a stored procedure in SQL Server 2008 R2 with the following parameter values declared:
@UN nvarchar(30),
@SN nvarchar(8),
@GG uniqueidentifier,
@Ss irnapp.SymbolTableType READONLY,
@SD date,
@ED date,
@IR nvarchar(1),
@ID nvarchar(1),
@NR int = NULL,
@GP nvarchar(1) = N'N'
It was my intention that if the @GP value is not supplied, then it should be given a value of N'N'. However, the procedure only returns the expected results when I explicitly pass in N'N' for @GP.
I've attempted searching for examples of SQL stored procedures with default parameter values, but the only examples I've found for nvarchar are defaults of NULL, which is not feasible for my application.
Would anyone know if the above is a legal default parameter declaration?
UPDATE:
Thanks Aaron for the quick response. I was hoping this would be a simple catch, as the code is quite lengthy. That said, here goes:
BEGIN TRY
DECLARE @GI int;
EXEC irn.GetGroupID @UN, @SN, @GG, @GI OUT;
DECLARE @CUID int;
IF @GP = N'Y'
BEGIN
SELECT @CUID = UserID
FROM Users
WHERE Uname = @UN
AND SNum = @SN;
END;
DECLARE @NoteIDs irn.NoteIDTableType;
INSERT INTO @NIDs (NO, NID)
SELECT *
FROM GetNIDs(@GI, @Ss, @SD, @ED, @IR, @ID, @NR, @GP, @CUID);
EXEC GetNsByNIDs @NIDs, N'N';
END TRY
BEGIN CATCH
EXEC irn.CreateProcedureErrorLog
EXEC irn.RaiseProcedureError
END CATCH;
ALTER FUNCTION [i].[GetNIDs] (
@GID int,
@Ss SymbolTableType READONLY,
@SD date,
@ED date,
@IR nvarchar(1),
@ID nvarchar(1),
@NR int,
@GP nvarchar(1) = N'N',
@CUID int = NULL)
RETURNS @TopOrderedMatchingNote TABLE (
NO int NOT NULL PRIMARY KEY,
NID int NOT NULL UNIQUE)
AS
BEGIN
INSERT INTO @MN (NID)
SELECT NID
FROM N
WHERE GID = @GID
AND ND >= @FDate
AND ND <= @TDate
AND IP = @GP
AND ((IP = N'Y' AND CUID = @CUID) OR (IP = N'N'))
AND IsDeleted = CASE @IncludeDeleted
WHEN N'N' THEN N'N'
ELSE IsDeleted
END;
END;
...snip...
Hope this is helpful and thanks again