Registered_User012345
Registered_User012345

Reputation: 79

Is it possible to insert to table even though the parameter is not supplied? sql

DECLARE @sample varchar(1)    
insert into tblSample (Column1) values(@sample)

then not passing any values to @sample.

I want to insert whenever I call the stored procedure even though the parameter is not supplied. Thanks

Upvotes: 0

Views: 71

Answers (3)

Jon R
Jon R

Reputation: 1

Either use a null default in a stored proc parameter, then set a default before the insert.

Or, you can set a default constraint on the table for that column.

Upvotes: 0

KumarHarsh
KumarHarsh

Reputation: 5094

why you will want to insert even if no parameter is supplied ?

what is the exACT REQUIREMENT ?

Upvotes: 0

Upendra Chaudhari
Upendra Chaudhari

Reputation: 6543

You can simply add default value NULL for parameter of SP. But make sure that your table allow NULL value in that column. If you will not pass any value to parameter then it will take NULL as default like below :

CREATE PROCEDURE TestProc (@sample varchar(1) = NULL)
AS
BEGIN
    insert into tblSample (Column1) values(@sample)
END

Upvotes: 2

Related Questions