If I have a trigger that returns a result set, is there a way to consume
that result set from T-SQL?
E.G.
CREATE TABLE T
( id identity(1,1),
data varchar(10) )
CREATE TRIGGER mytrigger
ON T
AFTER INSERT
AS
SELECT id FROM inserted
-- This doesn't work:
-- SELECT * FROM (INSERT T(data) SELECT otherData FROM AnotherTable)
-- I can do this and consume the result set at the client though...
INSERT T(data) SELECT otherData FROM AnotherTable
thank you.No, AFAIK thats not possible. If you really, really wanna do this you could
store the resultset in XML in an extra table and query for.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"jahyen" <jahyen@.> schrieb im Newsbeitrag
news:OwV7aQQSFHA.252@.TK2MSFTNGP12.phx.gbl...
> If I have a trigger that returns a result set, is there a way to consume
> that result set from T-SQL?
> E.G.
> CREATE TABLE T
> ( id identity(1,1),
> data varchar(10) )
> CREATE TRIGGER mytrigger
> ON T
> AFTER INSERT
> AS
> SELECT id FROM inserted
> -- This doesn't work:
> -- SELECT * FROM (INSERT T(data) SELECT otherData FROM AnotherTable)
> -- I can do this and consume the result set at the client though...
> INSERT T(data) SELECT otherData FROM AnotherTable
> thank you.
>
>|||No obvious way to do this. Why not just perform the INSERT and SELECT as
separate operations in a stored proc? That way you can handle the result any
way you choose.
David Portas
SQL Server MVP
--|||This is not the purpose of a trigger. A trigger is used to maintain
relationships within the schema, when you cannot use DRI actions. Do
the SELECT as a sepaarate statement.
No comments:
Post a Comment