How can I solve the error in the following procedure?
CREATE PROCEDURE cards
@salesman VARCHAR(10),
@RCV10 INT,
@RCV09 INT,
@RCV15 INT,
@GPRS15 INT,
@RCV20 INT,
@RCV25FTT INT,
@RCV25 INT,
@RCV31 INT,
@RCV30 INT,
@RCV35 INT,
@RCV50 INT,
@RCV55 INT,
@SIM INT,
@VTOPSIM INT,
@VTOPBAL INT,
@THREEGSIM INT,
@entrydate DATETIME
AS
BEGIN
IF EXISTS(
SELECT *
FROM CardsIssued
WHERE salesman = @salesman
AND RCV10 > @RCV10
AND RCV09 > @RCV09
AND RCV15 > @RCV15
AND GPRS15 > @GPRS15
AND RCV20 > @RCV20
AND RCV25FTT > @RCV25FTT
AND RCV25 > @RCV25
AND RCV31 > @RCV31
AND RCV30 > @RCV30
AND RCV35 > @RCV35
AND RCV50 > @RCV50
AND RCV55 > @RCV55
AND SIM > @SIM
AND VtopSim > @VTOPSIM
AND VtopBal > @VTOPBAL
AND ThreeGSim > @THREEGSIM
AND EntryDate = @entrydate
)
BEGIN
INSERT Cards_Returned
VALUES
(
@salesman,
@RCV10,
@RCV09,
@RCV15,
@GPRS15,
@RCV20,
@RCV25FTT,
@RCV25,
@RCV31,
@RCV30,
@RCV35,
@RCV50,
@RCV55,
@SIM,
@VTOPSIM,
@VTOPBAL,
@THREEGSIM,
@EntryDate
)
END
ELSE
PRINT'CARDS RETURNED CANNOT BE GREATER THAN CARDS ISSUED'
END
Run as:
execute cards 'S001',50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,'28/1/2013'
gives the following error:
Msg 8114, Level 16, State 5, Procedure cards, Line 0
Error converting data type varchar to datetime
'28/1/2013'
is an ambiguous format - SQL Server might interpret it as dd/mm/yyyy
or as mm/dd/yyyy
. In this case, it's done the latter, and doesn't know what the 28th month of the year is.
Use '20130128'
instead. This is always interpreted as yyyymmdd
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With