ALTER PROCEDURE companyinsert
@.companyid INT IDENTITY(1,1) NOT NULL,
@.companyname varchar(20),
@.address1 varchar(30)
AS
INSERT INTO companymaster
( companyname, address1)
VALUES (@.companyname,@.address1)
i don't want the companyname having the same names are recorded again with the different company id..
Can anyone help me and modify my code according it's giving error...in the @.companyid.
It is being done in sql server 2005 with asp.net C# 2005
You cannot declare a parameter with IDENTITY property in a stored proc. I think what you are looking for is more along these lines. You might want to read up documentation on SCOPE_IDENTITY(). Briefly, it returns the Identity value that was created due to your INSERT.
ALTER PROCEDURE companyinsert@.companyidINT OUTPUT,@.companynamevarchar(20),@.address1varchar(30)ASBEGINSET NOCOUNT ONIFNOT EXISTS(SELECT *FROM companymasterWHERE CompanyName = @.companynameAND Address1 = address1)BEGININSERT INTO companymaster ( companyname, address1)VALUES (@.companyname,@.address1)SELECT @.companyid = SCOPE_IDENTITY()ENDSET NOCOUNT OFFEND
No comments:
Post a Comment