0

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

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by yosepha
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.