Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Default Parameter in Stored Procedure call

I have the following stored procedure

CREATE PROCEDURE [dbo].[usp_GetData]
@foo VARCHAR (20), @bar bit = 1
AS ...

This provides the correct result when called in SSMS.

EXEC dbo.usp_GetData @foo = 'Hellow World', @bar = 0

Although when calling within a C# application as per below

cmd.Parameters.Add(new SqlParameter("@foo", foo)); 
cmd.Parameters.Add(new SqlParameter("@bar", 0));

& is captured by the profiler as below.

exec dbo.usp_GetData @foo=N'Hello World',@bar=default

Does a parameter that overides the default have to be passed differently?

like image 242
ojhawkins Avatar asked Sep 26 '13 23:09

ojhawkins


People also ask

What is default parameter in stored procedure?

The default is an input parameter. To specify an output parameter, the OUTPUT keyword must be specified in the definition of the parameter in the CREATE PROCEDURE statement. The procedure returns the current value of the output parameter to the calling program when the procedure exits.

Can pass 3 types of parameters to stored procedures What are they?

As a program, a stored procedure can take parameters. There are three types of parameters: IN, OUT and INOUT.

How do I execute a SQL stored procedure with parameters?

Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure. In the Execute Procedure dialog box, specify a value for each parameter and whether it should pass a null value.

Can we pass parameter in stored procedure?

You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is passed.


1 Answers

Use

cmd.Parameters.AddWithValue("@bar", 0)

This way you know you actually passing the value.

like image 174
Yuriy Galanter Avatar answered Oct 21 '22 06:10

Yuriy Galanter