Hi all,
Just a quick question.
I am calling a stored procedure which has two optional parameters.
Optional meaning they are declared with a default value NULL.
If for some reason and empty string send sent to the procedure will the
internal value of that parameter be NULL or "" ?
Area these the same thing in TSQL ?
Following on from that:
Will the Coalesce Function treat "" & NULL the same?
IE: I need to know if the following will result in 10 if an empty string is
sent to a stored procedure for the 'myParam' parameter..
CREATE PROCEDURE [dbo].[myProcedure]
@.myParam INT = NULL
As
BEGIN
SELECT * FROM myTable
WHERE myTableID = Coalesce(@.myParam,10)
END
Many thanks to those who respond!!!
Adam"Adam Knight" <adam@.pertrain.com.au> wrote in message
news:eNcdq2gyFHA.3860@.TK2MSFTNGP09.phx.gbl...
> Hi all,
> Just a quick question.
> I am calling a stored procedure which has two optional parameters.
> Optional meaning they are declared with a default value NULL.
> If for some reason and empty string send sent to the procedure will the
> internal value of that parameter be NULL or "" ?
An "Empty String" passed in as a parameter is treated as an empty string in
SQL ('')
> Area these the same thing in TSQL ?
A empty string, or zero-length string (ZLS) is not the same thing as NULL.
> Following on from that:
> Will the Coalesce Function treat "" & NULL the same?
COALESCE(value1, value2, ...) returns the first non-NULL value from the list
of values. A common usage of coalesce is something like this:
COALESCE(column, '')
To return a zero-length string in place of a NULL.
> IE: I need to know if the following will result in 10 if an empty string
> is sent to a stored procedure for the 'myParam' parameter..
> CREATE PROCEDURE [dbo].[myProcedure]
> @.myParam INT = NULL
> As
> BEGIN
> SELECT * FROM myTable
> WHERE myTableID = Coalesce(@.myParam,10)
> END
>
An empty string is not a NULL. You shouldn't be passing a 'string' value in
to this procedure anyway - it's an INT parameter. For your example would it
make sense to set the default for @.myParam INT = 10 and get rid of the
COALESCE() function call?
> Many thanks to those who respond!!!
> Adam
>
No comments:
Post a Comment