Ivor Williams said:
...
>> -----Original Message-----
>> From: Raf [mailto:[EMAIL PROTECTED]
...
>> I've got a :
>>
>> declare @foo int
>> select @foo=(some subselect)
>>
>> insert into table(f1, .. fn) values (v1, ...(select @foo),..vn)
>>
>> insert into table2(f1, ..., fn) values (v1...(select @foo),..vn)
>>
>
> Why do you want a select on @foo?
>
> @foo is a single (scalar) int

I was trying to avoid another flood of insert_id mails.

It's simply:
   <some insert>
   @foo=(select @@identity)
with that identity being inserted in a foreign key on each of the
subsequent tables.  I keep it in @foo, to avoid being clobbered by
subsequent @@identities.

>
> Presumably you want something like
> insert into table(f1, .. fn) values (v1, ... @foo, ..vn)

I'll give that a whirl.  I thought that I had to select the local
variable. Hmm.  I just tried it and I get:

DBD::Sybase::db do failed: Server message number=137 severity=15 state=2
line=9 server=pelicanprocedure=DBD6atext=Must declare variable
'@last_insert'.

Thus, I'm assuming that @foo falls out of scope at some stage.
Why?  How?

Please help?

Cheers,

R.




Reply via email to