I am trying to write my first sproc that inserts values into a table. These values will be entered by the user and stored in a variable . They will then be added to the database.

This is what I have come up with so far. I can't seem to get the syntax right. I don't know what is wrong with it. Please help. Thanks.

USE DataBase

CREATE PROC spInsertNewPet

@PetID int,
@CustID int,
@PetName varchar(20),
@BreedID int,
@Gender char(1),
@Weight decimal,
@DOB smalldatetime,
@DateFixed smalldatetime

INSERT INTO Pets(PetID, CustID, PetName, BreedID, Gender, Weight, DOB, DateFixed)
VALUES(@PetID, @CustID, @PetName, @BreedID, @Gender, @Weight, @DOB, @DateFixed)

GO

you are missingthe keyword 'AS' and would be easier to inser the date if you convert it into varchar. Here is the code.

alter PROC spInsertNewPet
(@PetID int,
@CustID int,
@PetName char(20),
@BreedID int,
@Gender char(1),
@Weight decimal,
@DOB smalldatetime ,
@DateFixed smalldatetime)
as

INSERT INTO DBO.Pet(PetID, CustID, PetName,
BreedID, Gender, Weight, DOB, DateFixed)
VALUES(@PetID, @CustID, @PetName, @BreedID,
@Gender, @Weight, cast (@DOB as varchar(30))
, cast( @DateFixed as varchar(30)))


I am trying to write my first sproc that inserts values into a table. These values will be entered by the user and stored in a variable . They will then be added to the database.

This is what I have come up with so far. I can't seem to get the syntax right. I don't know what is wrong with it. Please help. Thanks.

USE DataBase

CREATE PROC spInsertNewPet

@PetID int,
@CustID int,
@PetName varchar(20),
@BreedID int,
@Gender char(1),
@Weight decimal,
@DOB smalldatetime,
@DateFixed smalldatetime

INSERT INTO Pets(PetID, CustID, PetName, BreedID, Gender, Weight, DOB, DateFixed)
VALUES(@PetID, @CustID, @PetName, @BreedID, @Gender, @Weight, @DOB, @DateFixed)

GO

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.