cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michael.raffenb...@t-online.de (Michael Raffenberg)
Subject Re: Help with esql results for 'insert' query
Date Thu, 11 Jan 2001 20:25:51 GMT
Hello eliza,

Tuesday, January 09, 2001, 2:10:52 AM, you wrote:

ekTc> Hello,

ekTc> I am using MS SQL database and the tables are set up in a way that the
ekTc> primary keys get generated automatically when inserting entries.
ekTc> Is it feasible to get the generated id after 'insert' query in esql?

ekTc> Example:  I have a table called 'owners' with three columns: name, address,
ekTc> owner_id where owner_id is the primary key.

ekTc> After I insert as follows:
ekTc> <eql:execute-query>
ekTc>    <esql:query>insert into owners values('john smith')</esql:query>

ekTc> would query return the generated id for the entry that I just inserted? If
ekTc> so, what is the esql tags?  I don't seem to find it when looking at the
ekTc> esql logicsheet.  Please note that querying based on 'name' or 'address'
ekTc> will not help me because they are not necessarily unique, i.e. I could have
ekTc> entries with same names or address.

ekTc> Any help or suggestion is greatly appreciated.
ekTc> Eliza


ekTc> ---------------------------------------------------------------------
ekTc> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
ekTc> For additional commands, e-mail: cocoon-users-help@xml.apache.org

What about stored procedures?

I do it like this one:
CREATE PROCEDURE [dbo].[sp_InsertPersonalstamm]
        @Nachname               varchar (100),
        @Vorname                varchar (50), 
        @Username               varchar (50)  = NULL,
        @Anrede                 varchar (50),
        @Titel                  varchar (50) = NULL
AS
  DECLARE       @PersonID       int

  if ( (@NACHNAME is null or @NACHNAME ='') or (@VORNAME is NULL or @VORNAME ='') or (@ANREDE
is NULL or @Anrede ='') )
    Return -99

  /*create new record */
   INSERT INTO PERSONALSTAMM
   (NACHNAME, VORNAME, USERNAME, ANREDE, TITEL)
   VALUES    (@NACHNAME, @VORNAME, @USERNAME, @ANREDE, @TITEL)

  /* return the identity value from PersonID */
  set @PersonID = @@IDENTITY
  return @PersonID

-- 
Best regards,
 Michael                            mailto:michael.raffenberg@t-online.de



Mime
View raw message