May 31, 2010 at 4:18 am
hi there thanks for giving time for checking my problem.
problem is as follows :
I have a table as :
Id int PK
Name nvarchar(60) not null,
Signature nvarchar(100) not null,
PrivacyId int default '0' not null,
Visible bit default 'true' not null,
i want to create a stored procedure in such a way that the default values of the table can be inserted to to the table if user do not provide the respective data and if user provide the data the default data should be overridden by the new data passed by the user.
May 31, 2010 at 5:08 am
CREATE PROCEDURE TestD
@id int,
@Name nvarchar(60),
@Signature nvarchar(100),
@PrivacyId Int = 0,
@Visible bit = 0
AS
INSERT INTO #T
VALUES(@id,@name,@Signature,@PrivacyId,@Visible)
TestD 1,'First','whatever'
TestD 2,'Second','something',1,1
SELECT * FROM #T
Result:
IdNameSignaturePrivacyIdVisible
1Firstwhatever0 0
2Secondsomething1 1
From Books On Line (BOL) for 2008
Is a parameter in the procedure. One or more parameters can be declared in a CREATE PROCEDURE statement. The value of each declared parameter must be supplied by the user when the procedure is called, unless a default for the parameter is defined or the value is set to equal another parameter. A stored procedure can have a maximum of 2,100 parameters. If a procedure contains table-valued parameters, and the parameter is missing in the call, a default of empty table is passed in.
May 31, 2010 at 10:01 am
Thank you very much !!!!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply