Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

routine issue

Status
Not open for further replies.

griffitd

Programmer
Aug 20, 2002
189
GB
Hi i have the routine below. when called from vb.net i get CustomerID cannot be null. issue with iNewCId.

if a replace iNewCId with a number it works.

Please help

Thanks


-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `rModifyCustomer`(
IN CId INT,
IN CRef VARCHAR(45),
IN CName VARCHAR(45),
IN GendId INT,
IN TitId INT,
IN FName VARCHAR(30),
IN SName VARCHAR(30),
IN Init CHAR(2),
IN DateOB DATE
)
BEGIN
DECLARE iNewCId INT;

SELECT iNewCId = MAX(CustomerId) + 1 FROM
tblCustomer;

IF CId = -1 THEN
INSERT INTO tblCustomer
(
CustomerId,
CustomerRef,
CustomerName,
GenderId,
TitleId,
FirstName,
Surname,
Initial,
DOB
)
VALUES
(
iNewCId,
CRef,
CName,
GendId,
TitId,
FName,
SName,
Init,
DateOB
);
ELSE
UPDATE
tblCustomer
SET
CustomerRef = CRef,
CustomerName = CName,
GenderId = GendId,
TitleId = TitId,
FirstName = FName,
Surname= SName,
Initial = Init,
DOB = DateOB
WHERE CustomerId = CId;
END IF;
END
 
hi MYsql says syntax not allowed.

this is Mysql
not SQL server
Thanks
 
i posted an issue i have with MYSQL not sql server this is the MYSQL board!

 
I am pretty sure you will find Rudy is right.

I have looked at other My SQL tutorials and can not see variables declared with i preceding the name they all have @

@veriableName is the general convention for variables in SQL, I work with both SQL Server and Oracle and always use @. It seems unlikely that My SQL would be different.

Try changing iNewCId to @NewCId

Ian
 
@ does not work in MYSQL

it gets underlined and says syntax error!
 
Try Changing

SELECT iNewCId = MAX(CustomerId) + 1 FROM
tblCustomer;

to

set iNewCId = SELECT MAX(CustomerId) + 1 FROM
tblCustomer;

Ian
 
When using @ variables they are set using
@variable:=value

Note the colon, everything should work ;)

mysql> select @this:=curdate();
+------------------+
| @this:=curdate() |
+------------------+
| 2013-02-15 |
+------------------+
1 row in set (0.00 sec)

mysql> select @this;
+------------+
| @this |
+------------+
| 2013-02-15 |
+------------+
1 row in set (0.00 sec)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top