List:General Discussion« Previous MessageNext Message »
From:Pure Krome Date:November 17 2001 8:02am
Subject:[QUERY] Problem with Syntax/Query. Need Help Please.
View as plain text  
G'Day All.

I'm trying to do the following in a query, in mySQL.
All my previous years of SQL has been on MS-SQL, and i'm having some little
problems with tricky sql statements.

*****
i'm trying to insert a new record if the name doesn't exist in the table. If
i insert, return ID, else return 0
*****

<pseduo -sql syntax>

SET NOCOUNT ON

DECLARE @intPersonID   INTEGER

SELECT PersonID from tbl_PERSON WHERE Name = @strName
SELECT @intPersonID = @@IDENTITY

IF @intPersonID < 1
   BEGIN
      INSERT tbl_PERSON (Name, Surname) VALUES ('TestName', 'TestSurname')
      SELECT @intPersonID = @@IDENTITY
   END
ELSE
   SET @intPERSONID = 0

<end psedu untested code>

I have NO idea how i can do this on MYSQL..

Any help would be extreamly appreciated.

-Regards : Pure Krome-

Thread
[QUERY] Problem with Syntax/Query. Need Help Please.Pure Krome17 Nov
  • Re: [QUERY] Problem with Syntax/Query. Need Help Please.Tore Van Grembergen17 Nov