Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Learning Stored Procedure

Author  Topic 

aademeo
Starting Member

5 Posts

Posted - 2014-09-07 : 19:05:01
I'm working on creating a stored procedure that does an insert statement into the customers table and inserts the below values: '1000000100', 'Bruins', 'Bruin Way 1', 'Los Angeles', 'CA', '94005', 'USA', 'Joe Bruin', 'jbruin@ucla.edu');

Below is what I've developed, but I'm getting an error around SET and am not sure what's missing.

CREATE PROCEDURE usp_insertcustomers
@cust_id int, @CustName varchar(50), @CustAddress varcar(50), @CustCity varchar(50), @CustState varchar(5), @CustZipcode varchar(10), @CustCountry varchar(50), @CustContact varchar(50), @CustEmail varchar(225)

AS

INSERT INTO Customers

SET

cust_name = @CustName,
cust_address = @CustAddress,
cust_city = @CustCity,
cust_state = @CustState,
cust_zip = @CustZipcode,
cust_country = @CustCountry,
cust_contact = @CustContact,
cust_email = @CustEmail

WHERE cust_id = @cust_id

exec usp_insertcustomers
'1000000100', 'Bruins', 'Bruin Way 1', 'Los Angeles', 'CA', '94005', 'USA', 'Joe Bruin', 'jbruin@ucla.edu'

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-09-08 : 05:49:15
SET is used for update operation.
for insert it should be like this

CREATE PROCEDURE usp_insertcustomers @cust_id int, @CustName varchar(50), @CustAddress varcar(50), @CustCity varchar(50), @CustState varchar(5), @CustZipcode varchar(10), @CustCountry varchar(50), @CustContact varchar(50), @CustEmail varchar(225)

AS
BEGIN
INSERT INTO Customers (cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country,
cust_contact,
cust_email)
VALUES (@CustName, @CustAddress, @CustCity, @CustState, @CustZipcode, @CustCountry, @CustContact, @CustEmail)
END

Javeed Ahmed
Go to Top of Page
   

- Advertisement -