Hi Dan,

The double At symbol ( @@ ) also happens to have special meaning to
SQL-Server, as well as Witango.

This is where you need to use the <@LITERAL> Metatag so that you can pass
the phrase un-parsed by Witango directly to SQL-Server from inside your
Direct_DBMS Action, example:

<@LITERAL VALUE="@@IDENTITY>">

There are number of other Commands in SQL-Server that use these symbols like
@@ROWCOUNT and @@VERSION.

But as Klaus pointed out, this special command will return the 'identity
key' of the last inserted record for your table - but there is no guarantee
that the record was created by you, if more than one user is hitting the
table at the same time.

Like Bill Downall pointed out earlier, I also employ a UserID fields in all
my records so I can identify who created or modified a record, so I've been
playing with the following, to help ensure I pull back the Identity key for
my user.

SELECT <@LITERAL VALUE="@@IDENTITY"> As 'Identity' WHERE UserID =
'@@user$UserID'

Then you can find the new key value with:

<@VAR local$resultSet[1,Identity]>

Hope this helps. Cheers...


Scott Cadillac
http://xml-extra.net
[EMAIL PROTECTED]


----- Original Message -----
From: "Dan" <[EMAIL PROTECTED]>
To: "Multiple recipients of list witango-talk" <[EMAIL PROTECTED]>
Sent: Thursday, May 02, 2002 2:32 AM
Subject: Re: Witango-Talk: Finding out the new key in an insert action
inMS-SQL


> Klaus,
>
> Thanks for your reply, however I don't seem to get it right. Is it a
Witango
> variable of the system scope or user scope or ... you're talking about?
For
> me all of them are empty. Or should I run a direct Database SELECT
command?
> I would prefer not to have to run a query just to find a key, but then
> again, it's better than nothing. Would you please elaborate a little
more...
>
> Dan
>
> >
> > Dan,
> >
> > SELECT @@IDENTITY
> >
> > right after the insert does it for MS and Sybase SQL Server. But watch
out
> > for threading problems: @@IDENTITY is a system variable that always
holds the
> > value of the last auto-increment regardless of the table.
> >
> > Klaus
> >
> > On Wednesday 01 May 2002 03:21, Dan wrote:
> >> Hi,
> >>
> >> I've recently moved from FileMaker Mac to MSSQL PC.
> >> I have an "Identify" field in my tables (the database automatically
> >> generates the value for the keys). In Tango for FileMaker I used to
receive
> >> the record nr after the insert in the resultset so I could use it when
> >> needed to insert it into a related table. How do I do the equivalent in
> >> SQL? Thanks,
> >> Dan.
> >>
> >>
________________________________________________________________________
> >> TO UNSUBSCRIBE: send a plain text/US ASCII email to
[EMAIL PROTECTED]
> >> with unsubscribe witango-talk in the message body
> >
>
> ________________________________________________________________________
> TO UNSUBSCRIBE: send a plain text/US ASCII email to [EMAIL PROTECTED]
>                 with unsubscribe witango-talk in the message body
>

________________________________________________________________________
TO UNSUBSCRIBE: send a plain text/US ASCII email to [EMAIL PROTECTED]
                with unsubscribe witango-talk in the message body

Reply via email to