Tuesday, March 27, 2012

Calling stored proc with default params from .NET not working.

All,

I have the following :

ALTERPROCEDURE [dbo].[sp_FindNameJon]

@.NameNamevarchar(50)='',

@.NameAddressvarchar(50)='',

@.NameCityvarchar(50)='',

@.NameStatevarchar(2)='',

@.NameZipvarchar(15)='',

@.NamePhonevarchar(25)='',

@.NameTypeIdint=0,

@.BureauIdint,

@.Pageint=1,

@.Countint=100000

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SETNOCOUNTON;

DECLARE @.SqlStringnvarchar(3000),@.SelectClausenvarchar(1000), @.FromClausenvarchar(1000),@.WhereClausenvarchar(1000)

DECLARE @.ParentSqlStringnvarchar(4000)

DECLARE @.Startint, @.Endint

INSERTinto aaJonTempvalues(@.Page,'here2', @.NameCity);

And inside of aaJonTemp, I have the following :

NULLhere2NULLNULLhere2NULL

How is this possible? If @.Page or @.NameCity is NULL, how come it doesn't default to a value in the stored proc?

Thx

jonpfl

Because a parameter value being NULL is not the same thing as not supplying a parameter at all.

The defaults basically say... If the user hasn't supplied the parameter, then use this. You have supplied a parameter, although the value is NULL. If you want to make it so that if someone sends in a NULL and you want to change it to something else, then you need to code that.

IF @.param IS NULL SET @.param=...

sql

No comments:

Post a Comment