Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.
-
Newbie #1
trigger question
Hi
I have the following tables TranDetails (3rd Party) with 4 fields making up
primary key
Supplier char 7
GRN char 7
Journal decimal
JournalEntry decimal
detail1
detail1
detail3
InvMove
Journal (PK) decimal
JournalEntry (PK) decimal
Stockcode char
Supplier char
Date date
GRNDetails
GRN
Supplier
Stockcode
etc
when a record is inserted into the TranDetails table I would like to insert
a record into GRNDetails table based on a query from the InvMove and
TransDetails table.
I want the query to be limited to the record that has just been entered into
the TranDetails table i.e. the query would only ever return one record
How would I do this using a trigger? I am a complete beginner where this is
concerned so any help would be greatly appreciated
Newbie Guest
-
SQL Server Trigger question
Hi All, I have a cf app accessing data from a database that is controlled primarily by our MRP software. My problem isn't really ColdFusion... -
An trigger question
Hi,all: I want to create some trigger on an important database,my database is IDS2000. My question is: If exist a way to limit me only can create... -
question about trigger
Hello, I would like to use trigger to record change in every field (F1, F2, F3..) from table TAB1. CREATE TRIGGER TR1 AFTER UPDATE OF F1, F2,... -
Trigger question ...
We have about 50 customers in hosted environment, each running databases withi identical schema but different names. Part of the application traps... -
Simple trigger question
I'm real rusty with triggers..and I need one fairly quickly, so I would really appreaciate a bit of help. All I need to do: Upon insert or... -
Vishal Parkar #2
Re: trigger question
Make use of INSERTED temporary table,the inserted table stores copies of the
affected rows during INSERT. this table is visible to trigger body only. ie
if you are writing a trigger FOR INSERT operation, you can refer to this
table inside the trigger body.
See BOL for more information.
--
-Vishal
"Newbie" <noidea@nospam.com> wrote in message
news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...up> Hi
>
> I have the following tables TranDetails (3rd Party) with 4 fields makinginsert> primary key
> Supplier char 7
> GRN char 7
> Journal decimal
> JournalEntry decimal
> detail1
> detail1
> detail3
>
> InvMove
> Journal (PK) decimal
> JournalEntry (PK) decimal
> Stockcode char
> Supplier char
> Date date
>
>
> GRNDetails
> GRN
> Supplier
> Stockcode
> etc
>
>
> when a record is inserted into the TranDetails table I would like tointo> a record into GRNDetails table based on a query from the InvMove and
> TransDetails table.
> I want the query to be limited to the record that has just been enteredis> the TranDetails table i.e. the query would only ever return one record
>
> How would I do this using a trigger? I am a complete beginner where this> concerned so any help would be greatly appreciated
>
>
Vishal Parkar Guest
-
Newbie #3
Re: trigger question
Thanks for that but I am not sure understand what you mean . . . ..
Would I need to do something like:
CREATE TRIGGER newrecord
ON TranDetails
FOR INSERT
AS
SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
dbo.TranDetails.OrigReceiptDate
FROM dbo.TranDetailsINNER JOIN
dbo.InvMove ON dbo.GrnDetails.StockCode =
dbo.InvMove.StockCode
WHERE ???????
where should I be referencing the INSERTED temp table?
"Vishal Parkar" <vgparkar@hotmail.com> wrote in message
news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...the> Make use of INSERTED temporary table,the inserted table stores copies ofie> affected rows during INSERT. this table is visible to trigger body only.this> if you are writing a trigger FOR INSERT operation, you can refer to this
> table inside the trigger body.
> See BOL for more information.
>
> --
> -Vishal
> "Newbie" <noidea@nospam.com> wrote in message
> news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...> up> > Hi
> >
> > I have the following tables TranDetails (3rd Party) with 4 fields making> insert> > primary key
> > Supplier char 7
> > GRN char 7
> > Journal decimal
> > JournalEntry decimal
> > detail1
> > detail1
> > detail3
> >
> > InvMove
> > Journal (PK) decimal
> > JournalEntry (PK) decimal
> > Stockcode char
> > Supplier char
> > Date date
> >
> >
> > GRNDetails
> > GRN
> > Supplier
> > Stockcode
> > etc
> >
> >
> > when a record is inserted into the TranDetails table I would like to> into> > a record into GRNDetails table based on a query from the InvMove and
> > TransDetails table.
> > I want the query to be limited to the record that has just been entered> > the TranDetails table i.e. the query would only ever return one record
> >
> > How would I do this using a trigger? I am a complete beginner where> is>> > concerned so any help would be greatly appreciated
> >
> >
>
Newbie Guest
-
Newbie #4
Re: trigger question
Thanks but I'm still confused . . . . . :-(
where does the InvMove table come into the query?
does the inserted temp table just replace the references to the TranDetails
table?
i.e
SELECT a.Supplier, a.Grn,
a.OrigReceiptDate
FROM inserted a INNER JOIN
dbo.InvMove b ON a.StockCode =
b.StockCode
"Vishal Parkar" <vgparkar@hotmail.com> wrote in message
news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...as> INSERTED table will have same table design as triggering table ie
> TranDetails (same columnname/datatype) hence you can rewrite your queryof>
> SELECT a.Supplier, a.Grn,
> a.OrigReceiptDate
> FROM dbo.TranDetails a INNER JOIN inserted b on
> a.stockcode = b.stockcode
> where .....
>
> --
> -Vishal
> "Newbie" <noidea@nospam.com> wrote in message
> news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...> > Thanks for that but I am not sure understand what you mean . . . ..
> >
> > Would I need to do something like:
> >
> > CREATE TRIGGER newrecord
> > ON TranDetails
> > FOR INSERT
> > AS
> > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > dbo.TranDetails.OrigReceiptDate
> > FROM dbo.TranDetailsINNER JOIN
> > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > dbo.InvMove.StockCode
> > WHERE ???????
> >
> > where should I be referencing the INSERTED temp table?
> >
> >
> > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...> > > Make use of INSERTED temporary table,the inserted table stores copiesonly.> > the> > > affected rows during INSERT. this table is visible to trigger bodythis> > ie> > > if you are writing a trigger FOR INSERT operation, you can refer torecord> making> > > table inside the trigger body.
> > > See BOL for more information.
> > >
> > > --
> > > -Vishal
> > > "Newbie" <noidea@nospam.com> wrote in message
> > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > Hi
> > > >
> > > > I have the following tables TranDetails (3rd Party) with 4 fields> entered> > > up
> > > > primary key
> > > > Supplier char 7
> > > > GRN char 7
> > > > Journal decimal
> > > > JournalEntry decimal
> > > > detail1
> > > > detail1
> > > > detail3
> > > >
> > > > InvMove
> > > > Journal (PK) decimal
> > > > JournalEntry (PK) decimal
> > > > Stockcode char
> > > > Supplier char
> > > > Date date
> > > >
> > > >
> > > > GRNDetails
> > > > GRN
> > > > Supplier
> > > > Stockcode
> > > > etc
> > > >
> > > >
> > > > when a record is inserted into the TranDetails table I would like to
> > > insert
> > > > a record into GRNDetails table based on a query from the InvMove and
> > > > TransDetails table.
> > > > I want the query to be limited to the record that has just been> > > into
> > > > the TranDetails table i.e. the query would only ever return one>> > this> > > >
> > > > How would I do this using a trigger? I am a complete beginner where> >> > > is
> > > > concerned so any help would be greatly appreciated
> > > >
> > > >
> > >
> > >
> >
>
Newbie Guest
-
Vishal Parkar #5
Re: trigger question
are you trying to insert the records into inmove table? if yes then the
syntax would be.
insert into invmove(col1,col2,col2)
SELECT a.Supplier, a.Grn,
a.OrigReceiptDate
FROM dbo.TranDetails a INNER JOIN inserted b on
a.stockcode = b.stockcode
where .....
--
-Vishal
"Newbie" <noidea@nospam.com> wrote in message
news:esX$pQ#PDHA.3880@tk2msftngp13.phx.gbl...TranDetails> Thanks but I'm still confused . . . . . :-(
>
> where does the InvMove table come into the query?
> does the inserted temp table just replace the references to thecopies> table?
>
> i.e
>
> SELECT a.Supplier, a.Grn,
> a.OrigReceiptDate
> FROM inserted a INNER JOIN
> dbo.InvMove b ON a.StockCode =
> b.StockCode
>
>
> "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...> as> > INSERTED table will have same table design as triggering table ie
> > TranDetails (same columnname/datatype) hence you can rewrite your query> >
> > SELECT a.Supplier, a.Grn,
> > a.OrigReceiptDate
> > FROM dbo.TranDetails a INNER JOIN inserted b on
> > a.stockcode = b.stockcode
> > where .....
> >
> > --
> > -Vishal
> > "Newbie" <noidea@nospam.com> wrote in message
> > news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...> > > Thanks for that but I am not sure understand what you mean . . . ..
> > >
> > > Would I need to do something like:
> > >
> > > CREATE TRIGGER newrecord
> > > ON TranDetails
> > > FOR INSERT
> > > AS
> > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > dbo.TranDetails.OrigReceiptDate
> > > FROM dbo.TranDetailsINNER JOIN
> > > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > > dbo.InvMove.StockCode
> > > WHERE ???????
> > >
> > > where should I be referencing the INSERTED temp table?
> > >
> > >
> > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...
> > > > Make use of INSERTED temporary table,the inserted table storesto> of> only.> > > the
> > > > affected rows during INSERT. this table is visible to trigger body> this> > > ie
> > > > if you are writing a trigger FOR INSERT operation, you can refer to> > making> > > > table inside the trigger body.
> > > > See BOL for more information.
> > > >
> > > > --
> > > > -Vishal
> > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > > Hi
> > > > >
> > > > > I have the following tables TranDetails (3rd Party) with 4 fields> > > > up
> > > > > primary key
> > > > > Supplier char 7
> > > > > GRN char 7
> > > > > Journal decimal
> > > > > JournalEntry decimal
> > > > > detail1
> > > > > detail1
> > > > > detail3
> > > > >
> > > > > InvMove
> > > > > Journal (PK) decimal
> > > > > JournalEntry (PK) decimal
> > > > > Stockcode char
> > > > > Supplier char
> > > > > Date date
> > > > >
> > > > >
> > > > > GRNDetails
> > > > > GRN
> > > > > Supplier
> > > > > Stockcode
> > > > > etc
> > > > >
> > > > >
> > > > > when a record is inserted into the TranDetails table I would likeand> > > > insert
> > > > > a record into GRNDetails table based on a query from the InvMovewhere> record> > entered> > > > > TransDetails table.
> > > > > I want the query to be limited to the record that has just been> > > > into
> > > > > the TranDetails table i.e. the query would only ever return one> > > > >
> > > > > How would I do this using a trigger? I am a complete beginner>> >> > > this
> > > > is
> > > > > concerned so any help would be greatly appreciated
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Vishal Parkar Guest
-
Newbie #6
Re: trigger question
no I want to insert into table RECEIPTS (this syntax wasn't included before)
the results of the query
SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
dbo.TranDetails.OrigReceiptDate
FROM dbo.TranDetailsINNER JOIN
dbo.InvMove ON dbo.TranDetails.StockCode =
dbo.InvMove.StockCode
WHERE . . . the Grn = the Grn of the record that has just been inserted
into the TranDetails table
"Vishal Parkar" <vgparkar@hotmail.com> wrote in message
news:OyNGYT#PDHA.3144@tk2msftngp13.phx.gbl...query> are you trying to insert the records into inmove table? if yes then the
> syntax would be.
>
> insert into invmove(col1,col2,col2)
> SELECT a.Supplier, a.Grn,
> a.OrigReceiptDate
> FROM dbo.TranDetails a INNER JOIN inserted b on
> a.stockcode = b.stockcode
> where .....
>
> --
> -Vishal
> "Newbie" <noidea@nospam.com> wrote in message
> news:esX$pQ#PDHA.3880@tk2msftngp13.phx.gbl...> TranDetails> > Thanks but I'm still confused . . . . . :-(
> >
> > where does the InvMove table come into the query?
> > does the inserted temp table just replace the references to the> > table?
> >
> > i.e
> >
> > SELECT a.Supplier, a.Grn,
> > a.OrigReceiptDate
> > FROM inserted a INNER JOIN
> > dbo.InvMove b ON a.StockCode =
> > b.StockCode
> >
> >
> > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...> > > INSERTED table will have same table design as triggering table ie
> > > TranDetails (same columnname/datatype) hence you can rewrite your...> > as> > >
> > > SELECT a.Supplier, a.Grn,
> > > a.OrigReceiptDate
> > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > a.stockcode = b.stockcode
> > > where .....
> > >
> > > --
> > > -Vishal
> > > "Newbie" <noidea@nospam.com> wrote in message
> > > news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...
> > > > Thanks for that but I am not sure understand what you mean . . .to> copies> > > >
> > > > Would I need to do something like:
> > > >
> > > > CREATE TRIGGER newrecord
> > > > ON TranDetails
> > > > FOR INSERT
> > > > AS
> > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > dbo.TranDetails.OrigReceiptDate
> > > > FROM dbo.TranDetailsINNER JOIN
> > > > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > > > dbo.InvMove.StockCode
> > > > WHERE ???????
> > > >
> > > > where should I be referencing the INSERTED temp table?
> > > >
> > > >
> > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...
> > > > > Make use of INSERTED temporary table,the inserted table stores> > of> > only.> > > > the
> > > > > affected rows during INSERT. this table is visible to trigger body> > > > ie
> > > > > if you are writing a trigger FOR INSERT operation, you can referfields> > this> > > > > table inside the trigger body.
> > > > > See BOL for more information.
> > > > >
> > > > > --
> > > > > -Vishal
> > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > > > Hi
> > > > > >
> > > > > > I have the following tables TranDetails (3rd Party) with 4like> > > making
> > > > > up
> > > > > > primary key
> > > > > > Supplier char 7
> > > > > > GRN char 7
> > > > > > Journal decimal
> > > > > > JournalEntry decimal
> > > > > > detail1
> > > > > > detail1
> > > > > > detail3
> > > > > >
> > > > > > InvMove
> > > > > > Journal (PK) decimal
> > > > > > JournalEntry (PK) decimal
> > > > > > Stockcode char
> > > > > > Supplier char
> > > > > > Date date
> > > > > >
> > > > > >
> > > > > > GRNDetails
> > > > > > GRN
> > > > > > Supplier
> > > > > > Stockcode
> > > > > > etc
> > > > > >
> > > > > >
> > > > > > when a record is inserted into the TranDetails table I would> to> and> > > > > insert
> > > > > > a record into GRNDetails table based on a query from the InvMove> where> > record> > > > > > TransDetails table.
> > > > > > I want the query to be limited to the record that has just been
> > > entered
> > > > > into
> > > > > > the TranDetails table i.e. the query would only ever return one> > > > > >
> > > > > > How would I do this using a trigger? I am a complete beginner>> >> > > > this
> > > > > is
> > > > > > concerned so any help would be greatly appreciated
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Newbie Guest
-
Vishal Parkar #7
Re: trigger question
i assume you want to add INSERTED table as a join in the query. make sure
you are using proper fieldnames in join clause.
try:
SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
dbo.TranDetails.OrigReceiptDate
FROM dbo.TranDetailsINNER JOIN
dbo.InvMove ON dbo.TranDetails.StockCode =
dbo.InvMove.StockCode
WHERE dbo.TranDetails.Grn in
(select grn from inserted)
OR
SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
dbo.TranDetails.OrigReceiptDate
FROM dbo.TranDetails INNER JOIN
dbo.InvMove ON dbo.TranDetails.StockCode =
dbo.InvMove.StockCode inner join inserted on
inserted.grn = dbo.trandetails.grn
--
-Vishal
"Newbie" <noidea@nospam.com> wrote in message
news:#4bx4Y#PDHA.2768@tk2msftngp13.phx.gbl...before)> no I want to insert into table RECEIPTS (this syntax wasn't includedinserted> the results of the query
>
> SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> dbo.TranDetails.OrigReceiptDate
> FROM dbo.TranDetailsINNER JOIN
> dbo.InvMove ON dbo.TranDetails.StockCode =
> dbo.InvMove.StockCode
> WHERE . . . the Grn = the Grn of the record that has just beenbody> into the TranDetails table
>
>
>
> "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> news:OyNGYT#PDHA.3144@tk2msftngp13.phx.gbl...> query> > are you trying to insert the records into inmove table? if yes then the
> > syntax would be.
> >
> > insert into invmove(col1,col2,col2)
> > SELECT a.Supplier, a.Grn,
> > a.OrigReceiptDate
> > FROM dbo.TranDetails a INNER JOIN inserted b on
> > a.stockcode = b.stockcode
> > where .....
> >
> > --
> > -Vishal
> > "Newbie" <noidea@nospam.com> wrote in message
> > news:esX$pQ#PDHA.3880@tk2msftngp13.phx.gbl...> > TranDetails> > > Thanks but I'm still confused . . . . . :-(
> > >
> > > where does the InvMove table come into the query?
> > > does the inserted temp table just replace the references to the> > > table?
> > >
> > > i.e
> > >
> > > SELECT a.Supplier, a.Grn,
> > > a.OrigReceiptDate
> > > FROM inserted a INNER JOIN
> > > dbo.InvMove b ON a.StockCode =
> > > b.StockCode
> > >
> > >
> > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...
> > > > INSERTED table will have same table design as triggering table ie
> > > > TranDetails (same columnname/datatype) hence you can rewrite your> ..> > > as
> > > >
> > > > SELECT a.Supplier, a.Grn,
> > > > a.OrigReceiptDate
> > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > a.stockcode = b.stockcode
> > > > where .....
> > > >
> > > > --
> > > > -Vishal
> > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...
> > > > > Thanks for that but I am not sure understand what you mean . . .> > copies> > > > >
> > > > > Would I need to do something like:
> > > > >
> > > > > CREATE TRIGGER newrecord
> > > > > ON TranDetails
> > > > > FOR INSERT
> > > > > AS
> > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > dbo.TranDetails.OrigReceiptDate
> > > > > FROM dbo.TranDetailsINNER JOIN
> > > > > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > > > > dbo.InvMove.StockCode
> > > > > WHERE ???????
> > > > >
> > > > > where should I be referencing the INSERTED temp table?
> > > > >
> > > > >
> > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...
> > > > > > Make use of INSERTED temporary table,the inserted table stores> > > of
> > > > > the
> > > > > > affected rows during INSERT. this table is visible to triggerInvMove> to> > > only.
> > > > > ie
> > > > > > if you are writing a trigger FOR INSERT operation, you can refer> fields> > > this
> > > > > > table inside the trigger body.
> > > > > > See BOL for more information.
> > > > > >
> > > > > > --
> > > > > > -Vishal
> > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > > > > Hi
> > > > > > >
> > > > > > > I have the following tables TranDetails (3rd Party) with 4> like> > > > making
> > > > > > up
> > > > > > > primary key
> > > > > > > Supplier char 7
> > > > > > > GRN char 7
> > > > > > > Journal decimal
> > > > > > > JournalEntry decimal
> > > > > > > detail1
> > > > > > > detail1
> > > > > > > detail3
> > > > > > >
> > > > > > > InvMove
> > > > > > > Journal (PK) decimal
> > > > > > > JournalEntry (PK) decimal
> > > > > > > Stockcode char
> > > > > > > Supplier char
> > > > > > > Date date
> > > > > > >
> > > > > > >
> > > > > > > GRNDetails
> > > > > > > GRN
> > > > > > > Supplier
> > > > > > > Stockcode
> > > > > > > etc
> > > > > > >
> > > > > > >
> > > > > > > when a record is inserted into the TranDetails table I would> > to> > > > > > insert
> > > > > > > a record into GRNDetails table based on a query from thebeen> > and> > > > > > > TransDetails table.
> > > > > > > I want the query to be limited to the record that has justone> > > > entered
> > > > > > into
> > > > > > > the TranDetails table i.e. the query would only ever return>> > where> > > record
> > > > > > >
> > > > > > > How would I do this using a trigger? I am a complete beginner> >> > > > > this
> > > > > > is
> > > > > > > concerned so any help would be greatly appreciated
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Vishal Parkar Guest
-
Newbie #8
Re: trigger question
Thanks that seems to work :-) one last question . . .
If I wanted to limit the trigger to only inserting records into my table if
the qty < 0 for the record in the inserted table what would I need to add?
FYI I used the 1st option you gave using the subquery
Thanks
"Vishal Parkar" <vgparkar@hotmail.com> wrote in message
news:efhJXe#PDHA.2052@TK2MSFTNGP11.phx.gbl...the> i assume you want to add INSERTED table as a join in the query. make sure
> you are using proper fieldnames in join clause.
>
> try:
>
> SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> dbo.TranDetails.OrigReceiptDate
> FROM dbo.TranDetailsINNER JOIN
> dbo.InvMove ON dbo.TranDetails.StockCode =
> dbo.InvMove.StockCode
> WHERE dbo.TranDetails.Grn in
> (select grn from inserted)
>
> OR
>
> SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> dbo.TranDetails.OrigReceiptDate
> FROM dbo.TranDetails INNER JOIN
> dbo.InvMove ON dbo.TranDetails.StockCode =
> dbo.InvMove.StockCode inner join inserted on
> inserted.grn = dbo.trandetails.grn
>
>
> --
> -Vishal
> "Newbie" <noidea@nospam.com> wrote in message
> news:#4bx4Y#PDHA.2768@tk2msftngp13.phx.gbl...> before)> > no I want to insert into table RECEIPTS (this syntax wasn't included> inserted> > the results of the query
> >
> > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > dbo.TranDetails.OrigReceiptDate
> > FROM dbo.TranDetailsINNER JOIN
> > dbo.InvMove ON dbo.TranDetails.StockCode =
> > dbo.InvMove.StockCode
> > WHERE . . . the Grn = the Grn of the record that has just been> > into the TranDetails table
> >
> >
> >
> > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > news:OyNGYT#PDHA.3144@tk2msftngp13.phx.gbl...> > > are you trying to insert the records into inmove table? if yes then..> > query> > > syntax would be.
> > >
> > > insert into invmove(col1,col2,col2)
> > > SELECT a.Supplier, a.Grn,
> > > a.OrigReceiptDate
> > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > a.stockcode = b.stockcode
> > > where .....
> > >
> > > --
> > > -Vishal
> > > "Newbie" <noidea@nospam.com> wrote in message
> > > news:esX$pQ#PDHA.3880@tk2msftngp13.phx.gbl...
> > > > Thanks but I'm still confused . . . . . :-(
> > > >
> > > > where does the InvMove table come into the query?
> > > > does the inserted temp table just replace the references to the
> > > TranDetails
> > > > table?
> > > >
> > > > i.e
> > > >
> > > > SELECT a.Supplier, a.Grn,
> > > > a.OrigReceiptDate
> > > > FROM inserted a INNER JOIN
> > > > dbo.InvMove b ON a.StockCode =
> > > > b.StockCode
> > > >
> > > >
> > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...
> > > > > INSERTED table will have same table design as triggering table ie
> > > > > TranDetails (same columnname/datatype) hence you can rewrite your> > > > as
> > > > >
> > > > > SELECT a.Supplier, a.Grn,
> > > > > a.OrigReceiptDate
> > > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > > a.stockcode = b.stockcode
> > > > > where .....
> > > > >
> > > > > --
> > > > > -Vishal
> > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...
> > > > > > Thanks for that but I am not sure understand what you mean . .refer> body> > ..> > > > > >
> > > > > > Would I need to do something like:
> > > > > >
> > > > > > CREATE TRIGGER newrecord
> > > > > > ON TranDetails
> > > > > > FOR INSERT
> > > > > > AS
> > > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > > dbo.TranDetails.OrigReceiptDate
> > > > > > FROM dbo.TranDetailsINNER JOIN
> > > > > > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > > > > > dbo.InvMove.StockCode
> > > > > > WHERE ???????
> > > > > >
> > > > > > where should I be referencing the INSERTED temp table?
> > > > > >
> > > > > >
> > > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...
> > > > > > > Make use of INSERTED temporary table,the inserted table stores
> > > copies
> > > > of
> > > > > > the
> > > > > > > affected rows during INSERT. this table is visible to trigger> > > > only.
> > > > > > ie
> > > > > > > if you are writing a trigger FOR INSERT operation, you canbeginner> InvMove> > to> > fields> > > > this
> > > > > > > table inside the trigger body.
> > > > > > > See BOL for more information.
> > > > > > >
> > > > > > > --
> > > > > > > -Vishal
> > > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > > > > > Hi
> > > > > > > >
> > > > > > > > I have the following tables TranDetails (3rd Party) with 4> > like> > > > > making
> > > > > > > up
> > > > > > > > primary key
> > > > > > > > Supplier char 7
> > > > > > > > GRN char 7
> > > > > > > > Journal decimal
> > > > > > > > JournalEntry decimal
> > > > > > > > detail1
> > > > > > > > detail1
> > > > > > > > detail3
> > > > > > > >
> > > > > > > > InvMove
> > > > > > > > Journal (PK) decimal
> > > > > > > > JournalEntry (PK) decimal
> > > > > > > > Stockcode char
> > > > > > > > Supplier char
> > > > > > > > Date date
> > > > > > > >
> > > > > > > >
> > > > > > > > GRNDetails
> > > > > > > > GRN
> > > > > > > > Supplier
> > > > > > > > Stockcode
> > > > > > > > etc
> > > > > > > >
> > > > > > > >
> > > > > > > > when a record is inserted into the TranDetails table I would> > > to
> > > > > > > insert
> > > > > > > > a record into GRNDetails table based on a query from the> been> > > and
> > > > > > > > TransDetails table.
> > > > > > > > I want the query to be limited to the record that has just> one> > > > > entered
> > > > > > > into
> > > > > > > > the TranDetails table i.e. the query would only ever return> > > > record
> > > > > > > >
> > > > > > > > How would I do this using a trigger? I am a complete>> >> > > where
> > > > > > this
> > > > > > > is
> > > > > > > > concerned so any help would be greatly appreciated
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Newbie Guest
-
Vishal Parkar #9
Re: trigger question
add where cluase to the query
ex:
SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
dbo.TranDetails.OrigReceiptDate
FROM dbo.TranDetails INNER JOIN
dbo.InvMove ON dbo.TranDetails.StockCode =
dbo.InvMove.StockCode inner join inserted on
inserted.grn = dbo.trandetails.grn
where inserted.qty < 0--check this condition and use right column name.
--
-Vishal
"Newbie" <noidea@nospam.com> wrote in message
news:eNG5Sd$PDHA.3144@tk2msftngp13.phx.gbl...if> Thanks that seems to work :-) one last question . . .
>
> If I wanted to limit the trigger to only inserting records into my tableadd?> the qty < 0 for the record in the inserted table what would I need tosure>
> FYI I used the 1st option you gave using the subquery
>
> Thanks
> "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> news:efhJXe#PDHA.2052@TK2MSFTNGP11.phx.gbl...> > i assume you want to add INSERTED table as a join in the query. makeie> the> > you are using proper fieldnames in join clause.
> >
> > try:
> >
> > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > dbo.TranDetails.OrigReceiptDate
> > FROM dbo.TranDetailsINNER JOIN
> > dbo.InvMove ON dbo.TranDetails.StockCode =
> > dbo.InvMove.StockCode
> > WHERE dbo.TranDetails.Grn in
> > (select grn from inserted)
> >
> > OR
> >
> > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > dbo.TranDetails.OrigReceiptDate
> > FROM dbo.TranDetails INNER JOIN
> > dbo.InvMove ON dbo.TranDetails.StockCode =
> > dbo.InvMove.StockCode inner join inserted on
> > inserted.grn = dbo.trandetails.grn
> >
> >
> > --
> > -Vishal
> > "Newbie" <noidea@nospam.com> wrote in message
> > news:#4bx4Y#PDHA.2768@tk2msftngp13.phx.gbl...> > before)> > > no I want to insert into table RECEIPTS (this syntax wasn't included> > inserted> > > the results of the query
> > >
> > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > dbo.TranDetails.OrigReceiptDate
> > > FROM dbo.TranDetailsINNER JOIN
> > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > dbo.InvMove.StockCode
> > > WHERE . . . the Grn = the Grn of the record that has just been> > > into the TranDetails table
> > >
> > >
> > >
> > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > news:OyNGYT#PDHA.3144@tk2msftngp13.phx.gbl...
> > > > are you trying to insert the records into inmove table? if yes then> > > > syntax would be.
> > > >
> > > > insert into invmove(col1,col2,col2)
> > > > SELECT a.Supplier, a.Grn,
> > > > a.OrigReceiptDate
> > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > a.stockcode = b.stockcode
> > > > where .....
> > > >
> > > > --
> > > > -Vishal
> > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > news:esX$pQ#PDHA.3880@tk2msftngp13.phx.gbl...
> > > > > Thanks but I'm still confused . . . . . :-(
> > > > >
> > > > > where does the InvMove table come into the query?
> > > > > does the inserted temp table just replace the references to the
> > > > TranDetails
> > > > > table?
> > > > >
> > > > > i.e
> > > > >
> > > > > SELECT a.Supplier, a.Grn,
> > > > > a.OrigReceiptDate
> > > > > FROM inserted a INNER JOIN
> > > > > dbo.InvMove b ON a.StockCode =
> > > > > b.StockCode
> > > > >
> > > > >
> > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...
> > > > > > INSERTED table will have same table design as triggering tableyour> > > > > > TranDetails (same columnname/datatype) hence you can rewrite..> > > query
> > > > > as
> > > > > >
> > > > > > SELECT a.Supplier, a.Grn,
> > > > > > a.OrigReceiptDate
> > > > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > > > a.stockcode = b.stockcode
> > > > > > where .....
> > > > > >
> > > > > > --
> > > > > > -Vishal
> > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...
> > > > > > > Thanks for that but I am not sure understand what you mean .stores> .> > > ..
> > > > > > >
> > > > > > > Would I need to do something like:
> > > > > > >
> > > > > > > CREATE TRIGGER newrecord
> > > > > > > ON TranDetails
> > > > > > > FOR INSERT
> > > > > > > AS
> > > > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > > > dbo.TranDetails.OrigReceiptDate
> > > > > > > FROM dbo.TranDetailsINNER JOIN
> > > > > > > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > > > > > > dbo.InvMove.StockCode
> > > > > > > WHERE ???????
> > > > > > >
> > > > > > > where should I be referencing the INSERTED temp table?
> > > > > > >
> > > > > > >
> > > > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > > > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...
> > > > > > > > Make use of INSERTED temporary table,the inserted tabletrigger> > > > copies
> > > > > of
> > > > > > > the
> > > > > > > > affected rows during INSERT. this table is visible towould> refer> > body> > > > > only.
> > > > > > > ie
> > > > > > > > if you are writing a trigger FOR INSERT operation, you can> > > to
> > > > > this
> > > > > > > > table inside the trigger body.
> > > > > > > > See BOL for more information.
> > > > > > > >
> > > > > > > > --
> > > > > > > > -Vishal
> > > > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > > > > > > Hi
> > > > > > > > >
> > > > > > > > > I have the following tables TranDetails (3rd Party) with 4
> > > fields
> > > > > > making
> > > > > > > > up
> > > > > > > > > primary key
> > > > > > > > > Supplier char 7
> > > > > > > > > GRN char 7
> > > > > > > > > Journal decimal
> > > > > > > > > JournalEntry decimal
> > > > > > > > > detail1
> > > > > > > > > detail1
> > > > > > > > > detail3
> > > > > > > > >
> > > > > > > > > InvMove
> > > > > > > > > Journal (PK) decimal
> > > > > > > > > JournalEntry (PK) decimal
> > > > > > > > > Stockcode char
> > > > > > > > > Supplier char
> > > > > > > > > Date date
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > GRNDetails
> > > > > > > > > GRN
> > > > > > > > > Supplier
> > > > > > > > > Stockcode
> > > > > > > > > etc
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > when a record is inserted into the TranDetails table Ireturn> > InvMove> > > like
> > > > to
> > > > > > > > insert
> > > > > > > > > a record into GRNDetails table based on a query from the> > been> > > > and
> > > > > > > > > TransDetails table.
> > > > > > > > > I want the query to be limited to the record that has just> > > > > > entered
> > > > > > > > into
> > > > > > > > > the TranDetails table i.e. the query would only ever> beginner> > one> > > > > record
> > > > > > > > >
> > > > > > > > > How would I do this using a trigger? I am a complete>> >> > > > where
> > > > > > > this
> > > > > > > > is
> > > > > > > > > concerned so any help would be greatly appreciated
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Vishal Parkar Guest
-
Newbie #10
Re: trigger question
Thanks for your help but I couldn't get this to work
Here is what I have so far but this puts records in the table without any
regard to qty - I want to be able to limit it to negative records
What do I do ?
CREATE TRIGGER receipts ON[dbo].[GrnDetails]
FOR INSERT
AS
insert into RejectTrigger(GRD.Supplier,
GRD.Grn,
GRD.PurchaseOrder,
GRD.PurchaseOrderLin,
GRD.StockCode,
GRD.QtyReceived,
GRD.QtyUom,
GRD.DeliveryNote,
GRD.OrigReceiptDate,
INM.LongDesc)
SELECT DISTINCT
GRD.Supplier,
GRD.Grn,
GRD.PurchaseOrder,
GRD.PurchaseOrderLin,
GRD.StockCode,
GRD.QtyReceived,
GRD.QtyUom,
GRD.DeliveryNote,
GRD.OrigReceiptDate,
INM.LongDesc
FROM dbo.GrnDetails GRD INNER JOIN
dbo.ApSupplier APM
ON GRD.Supplier = APM.Supplier INNER JOIN
dbo.ApSupplierAddr APA
ON APM.Supplier = APA.Supplier LEFT OUTER JOIN
dbo.InvJournalDet IJD
ON GRD.Journal = IJD.Journal AND
GRD.JournalEntry = IJD.EntryNumber LEFT OUTER JOIN
dbo.InvMaster INM
ON GRD.StockCode = INM.StockCode LEFT OUTER JOIN
dbo.InvSerialTrn IST
ON GRD.Grn = IST.Reference
Where GRD.Grn in
(select distinct inserted.Grn from inserted )
"Vishal Parkar" <vgparkar@hotmail.com> wrote in message
news:e0b86m$PDHA.2052@TK2MSFTNGP11.phx.gbl...then> add where cluase to the query
> ex:
> SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> dbo.TranDetails.OrigReceiptDate
> FROM dbo.TranDetails INNER JOIN
> dbo.InvMove ON dbo.TranDetails.StockCode =
> dbo.InvMove.StockCode inner join inserted on
> inserted.grn = dbo.trandetails.grn
> where inserted.qty < 0--check this condition and use right column name.
>
> --
> -Vishal
> "Newbie" <noidea@nospam.com> wrote in message
> news:eNG5Sd$PDHA.3144@tk2msftngp13.phx.gbl...> if> > Thanks that seems to work :-) one last question . . .
> >
> > If I wanted to limit the trigger to only inserting records into my table> add?> > the qty < 0 for the record in the inserted table what would I need to> sure> >
> > FYI I used the 1st option you gave using the subquery
> >
> > Thanks
> > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > news:efhJXe#PDHA.2052@TK2MSFTNGP11.phx.gbl...> > > i assume you want to add INSERTED table as a join in the query. make> > > you are using proper fieldnames in join clause.
> > >
> > > try:
> > >
> > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > dbo.TranDetails.OrigReceiptDate
> > > FROM dbo.TranDetailsINNER JOIN
> > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > dbo.InvMove.StockCode
> > > WHERE dbo.TranDetails.Grn in
> > > (select grn from inserted)
> > >
> > > OR
> > >
> > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > dbo.TranDetails.OrigReceiptDate
> > > FROM dbo.TranDetails INNER JOIN
> > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > dbo.InvMove.StockCode inner join inserted on
> > > inserted.grn = dbo.trandetails.grn
> > >
> > >
> > > --
> > > -Vishal
> > > "Newbie" <noidea@nospam.com> wrote in message
> > > news:#4bx4Y#PDHA.2768@tk2msftngp13.phx.gbl...
> > > > no I want to insert into table RECEIPTS (this syntax wasn't included
> > > before)
> > > > the results of the query
> > > >
> > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > dbo.TranDetails.OrigReceiptDate
> > > > FROM dbo.TranDetailsINNER JOIN
> > > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > > dbo.InvMove.StockCode
> > > > WHERE . . . the Grn = the Grn of the record that has just been
> > > inserted
> > > > into the TranDetails table
> > > >
> > > >
> > > >
> > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > news:OyNGYT#PDHA.3144@tk2msftngp13.phx.gbl...
> > > > > are you trying to insert the records into inmove table? if yestable> > the> > > > > syntax would be.
> > > > >
> > > > > insert into invmove(col1,col2,col2)
> > > > > SELECT a.Supplier, a.Grn,
> > > > > a.OrigReceiptDate
> > > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > > a.stockcode = b.stockcode
> > > > > where .....
> > > > >
> > > > > --
> > > > > -Vishal
> > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > news:esX$pQ#PDHA.3880@tk2msftngp13.phx.gbl...
> > > > > > Thanks but I'm still confused . . . . . :-(
> > > > > >
> > > > > > where does the InvMove table come into the query?
> > > > > > does the inserted temp table just replace the references to the
> > > > > TranDetails
> > > > > > table?
> > > > > >
> > > > > > i.e
> > > > > >
> > > > > > SELECT a.Supplier, a.Grn,
> > > > > > a.OrigReceiptDate
> > > > > > FROM inserted a INNER JOIN
> > > > > > dbo.InvMove b ON a.StockCode =
> > > > > > b.StockCode
> > > > > >
> > > > > >
> > > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > > news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...
> > > > > > > INSERTED table will have same table design as triggering..> ie> your> > > > > > > TranDetails (same columnname/datatype) hence you can rewrite> > > > query
> > > > > > as
> > > > > > >
> > > > > > > SELECT a.Supplier, a.Grn,
> > > > > > > a.OrigReceiptDate
> > > > > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > > > > a.stockcode = b.stockcode
> > > > > > > where .....
> > > > > > >
> > > > > > > --
> > > > > > > -Vishal
> > > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > > news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...
> > > > > > > > Thanks for that but I am not sure understand what you mean4> .> stores> > .> > > > ..
> > > > > > > >
> > > > > > > > Would I need to do something like:
> > > > > > > >
> > > > > > > > CREATE TRIGGER newrecord
> > > > > > > > ON TranDetails
> > > > > > > > FOR INSERT
> > > > > > > > AS
> > > > > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > > > > dbo.TranDetails.OrigReceiptDate
> > > > > > > > FROM dbo.TranDetailsINNER JOIN
> > > > > > > > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > > > > > > > dbo.InvMove.StockCode
> > > > > > > > WHERE ???????
> > > > > > > >
> > > > > > > > where should I be referencing the INSERTED temp table?
> > > > > > > >
> > > > > > > >
> > > > > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > > > > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...
> > > > > > > > > Make use of INSERTED temporary table,the inserted table> trigger> > > > > copies
> > > > > > of
> > > > > > > > the
> > > > > > > > > affected rows during INSERT. this table is visible to> > refer> > > body
> > > > > > only.
> > > > > > > > ie
> > > > > > > > > if you are writing a trigger FOR INSERT operation, you can> > > > to
> > > > > > this
> > > > > > > > > table inside the trigger body.
> > > > > > > > > See BOL for more information.
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > -Vishal
> > > > > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > > > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > > > > > > > Hi
> > > > > > > > > >
> > > > > > > > > > I have the following tables TranDetails (3rd Party) withjust> would> > > > fields
> > > > > > > making
> > > > > > > > > up
> > > > > > > > > > primary key
> > > > > > > > > > Supplier char 7
> > > > > > > > > > GRN char 7
> > > > > > > > > > Journal decimal
> > > > > > > > > > JournalEntry decimal
> > > > > > > > > > detail1
> > > > > > > > > > detail1
> > > > > > > > > > detail3
> > > > > > > > > >
> > > > > > > > > > InvMove
> > > > > > > > > > Journal (PK) decimal
> > > > > > > > > > JournalEntry (PK) decimal
> > > > > > > > > > Stockcode char
> > > > > > > > > > Supplier char
> > > > > > > > > > Date date
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > GRNDetails
> > > > > > > > > > GRN
> > > > > > > > > > Supplier
> > > > > > > > > > Stockcode
> > > > > > > > > > etc
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > when a record is inserted into the TranDetails table I> > > > like
> > > > > to
> > > > > > > > > insert
> > > > > > > > > > a record into GRNDetails table based on a query from the
> > > InvMove
> > > > > and
> > > > > > > > > > TransDetails table.
> > > > > > > > > > I want the query to be limited to the record that has> return> > > been
> > > > > > > entered
> > > > > > > > > into
> > > > > > > > > > the TranDetails table i.e. the query would only ever>> > beginner> > > one
> > > > > > record
> > > > > > > > > >
> > > > > > > > > > How would I do this using a trigger? I am a complete> >> > > > > where
> > > > > > > > this
> > > > > > > > > is
> > > > > > > > > > concerned so any help would be greatly appreciated
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Newbie Guest
-
Newbie #11
Re: trigger question
Thanks but it still doesn't work :-(
the problem I have now is that when a negative record is added to the
GrnDetails table the trigger is adding two records to the GRN table because
each negative has to be linked to a positive Grn.
The primary key on the GrnDetails table are Grn, Journal, JournalEntry and
GrnSource therefore the subquery which just asks for the Grn to be included
is returning two records - one positive and one negative
How can I limit the subquery to take account of the Journal, JournalEnrty,
GrnSource and Grn?
FYI here is the query so far . .
insert into MIS.dbo.GRN(GRD.Supplier,
GRD.Grn,
GRD.Journal,
GRD.JournalEntry,
GRD.GrnSource,
IST.Serial,
GRD.PurchaseOrder,
GRD.PurchaseOrderLin,
GRD.StockCode,
GRD.QtyReceived,
GRD.QtyUom,
GRD.DeliveryNote,
GRD.OrigReceiptDate,
INM.[Description],
INM.LongDesc,
INM.DrawOfficeNum,
APA.SupAddr1,
APA.SupAddr2,
APA.SupAddr3,
APM.SupplierClass,
APA.SupAddr5,
APA.SupAddr4,
APA.SupPostalCode,
IJD.Notation,
IJD.RejectCode,
APM.SupplierName)
SELECT DISTINCT
GRD.Supplier,
GRD.Grn,
GRD.Journal,
GRD.JournalEntry,
GRD.GrnSource,
IST.Serial,
GRD.PurchaseOrder,
GRD.PurchaseOrderLin,
GRD.StockCode,
GRD.QtyReceived,
GRD.QtyUom,
GRD.DeliveryNote,
GRD.OrigReceiptDate,
INM.[Description],
INM.LongDesc,
INM.DrawOfficeNum,
APA.SupAddr1,
APA.SupAddr2,
APA.SupAddr3,
APM.SupplierClass,
APA.SupAddr5,
APA.SupAddr4,
APA.SupPostalCode,
IJD.Notation,
IJD.RejectCode,
APM.SupplierName
FROM dbo.GrnDetails GRD INNER JOIN
dbo.ApSupplier APM
ON GRD.Supplier = APM.Supplier INNER JOIN
dbo.ApSupplierAddr APA
ON APM.Supplier = APA.Supplier LEFT OUTER JOIN
dbo.InvJournalDet IJD
ON GRD.Journal = IJD.Journal AND
GRD.JournalEntry = IJD.EntryNumber AND
GRD.GrnSource = IJD.GrnSource LEFT OUTER JOIN
dbo.InvMaster INM
ON GRD.StockCode = INM.StockCode LEFT OUTER JOIN
dbo.InvSerialTrn IST
ON GRD.Grn = IST.Reference
Where GRD.Grn in
(select distinct inserted.Grn from inserted INNER JOIN dbo.GrnDetails GRD2
ON inserted.JournalEntry = GRD2.JournalEntry AND inserted.Journal =
GRD2.Journal and inserted.Grn = GRD2.Grn and inserted.GrnSource =
GRD2.GrnSource)
"Vishal Parkar" <vgparkar@hotmail.com> wrote in message
news:utBoJtIQDHA.2832@TK2MSFTNGP10.phx.gbl...any> Try:
> insert into RejectTrigger(GRD.Supplier,
> GRD.Grn,
> GRD.PurchaseOrder,
> GRD.PurchaseOrderLin,
> GRD.StockCode,
> GRD.QtyReceived,
> GRD.QtyUom,
> GRD.DeliveryNote,
> GRD.OrigReceiptDate,
> INM.LongDesc)
> SELECT DISTINCT
> GRD.Supplier,
> GRD.Grn,
> GRD.PurchaseOrder,
> GRD.PurchaseOrderLin,
> GRD.StockCode,
> GRD.QtyReceived,
> GRD.QtyUom,
> GRD.DeliveryNote,
> GRD.OrigReceiptDate,
> INM.LongDesc
>
> FROM dbo.GrnDetails GRD INNER JOIN
>
> dbo.ApSupplier APM
> ON GRD.Supplier = APM.Supplier INNER JOIN
>
> dbo.ApSupplierAddr APA
> ON APM.Supplier = APA.Supplier LEFT OUTER JOIN
>
> dbo.InvJournalDet IJD
> ON GRD.Journal = IJD.Journal AND
> GRD.JournalEntry = IJD.EntryNumber LEFT OUTER JOIN
>
> dbo.InvMaster INM
> ON GRD.StockCode = INM.StockCode LEFT OUTER JOIN
>
> dbo.InvSerialTrn IST
> ON GRD.Grn = IST.Reference
> Where GRD.Grn in
> (select distinct inserted.Grn from inserted where inserted.qty < 0 ) --if
> you want to have negative records / change the condition to > 0 to have
> positive value records.
>
> --
> -Vishal
> "Newbie" <noidea@nospam.com> wrote in message
> news:#$X1A2$PDHA.1720@TK2MSFTNGP11.phx.gbl...> > Thanks for your help but I couldn't get this to work
> >
> > Here is what I have so far but this puts records in the table withoutname.> > regard to qty - I want to be able to limit it to negative records
> >
> > What do I do ?
> >
> >
> > CREATE TRIGGER receipts ON[dbo].[GrnDetails]
> > FOR INSERT
> > AS
> > insert into RejectTrigger(GRD.Supplier,
> > GRD.Grn,
> > GRD.PurchaseOrder,
> > GRD.PurchaseOrderLin,
> > GRD.StockCode,
> > GRD.QtyReceived,
> > GRD.QtyUom,
> > GRD.DeliveryNote,
> > GRD.OrigReceiptDate,
> > INM.LongDesc)
> > SELECT DISTINCT
> > GRD.Supplier,
> > GRD.Grn,
> > GRD.PurchaseOrder,
> > GRD.PurchaseOrderLin,
> > GRD.StockCode,
> > GRD.QtyReceived,
> > GRD.QtyUom,
> > GRD.DeliveryNote,
> > GRD.OrigReceiptDate,
> > INM.LongDesc
> >
> >
> > FROM dbo.GrnDetails GRD INNER JOIN
> >
> > dbo.ApSupplier APM
> > ON GRD.Supplier = APM.Supplier INNER JOIN
> >
> > dbo.ApSupplierAddr APA
> > ON APM.Supplier = APA.Supplier LEFT OUTER JOIN
> >
> > dbo.InvJournalDet IJD
> > ON GRD.Journal = IJD.Journal AND
> > GRD.JournalEntry = IJD.EntryNumber LEFT OUTER JOIN
> >
> > dbo.InvMaster INM
> > ON GRD.StockCode = INM.StockCode LEFT OUTER JOIN
> >
> > dbo.InvSerialTrn IST
> > ON GRD.Grn = IST.Reference
> > Where GRD.Grn in
> > (select distinct inserted.Grn from inserted )
> >
> >
> > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > news:e0b86m$PDHA.2052@TK2MSFTNGP11.phx.gbl...> > > add where cluase to the query
> > > ex:
> > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > dbo.TranDetails.OrigReceiptDate
> > > FROM dbo.TranDetails INNER JOIN
> > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > dbo.InvMove.StockCode inner join inserted on
> > > inserted.grn = dbo.trandetails.grn
> > > where inserted.qty < 0--check this condition and use right columnto> table> > >
> > > --
> > > -Vishal
> > > "Newbie" <noidea@nospam.com> wrote in message
> > > news:eNG5Sd$PDHA.3144@tk2msftngp13.phx.gbl...
> > > > Thanks that seems to work :-) one last question . . .
> > > >
> > > > If I wanted to limit the trigger to only inserting records into my> > > if
> > > > the qty < 0 for the record in the inserted table what would I needmake> > > add?
> > > >
> > > > FYI I used the 1st option you gave using the subquery
> > > >
> > > > Thanks
> > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > news:efhJXe#PDHA.2052@TK2MSFTNGP11.phx.gbl...
> > > > > i assume you want to add INSERTED table as a join in the query.been> included> > > sure
> > > > > you are using proper fieldnames in join clause.
> > > > >
> > > > > try:
> > > > >
> > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > dbo.TranDetails.OrigReceiptDate
> > > > > FROM dbo.TranDetailsINNER JOIN
> > > > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > > > dbo.InvMove.StockCode
> > > > > WHERE dbo.TranDetails.Grn in
> > > > > (select grn from inserted)
> > > > >
> > > > > OR
> > > > >
> > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > dbo.TranDetails.OrigReceiptDate
> > > > > FROM dbo.TranDetails INNER JOIN
> > > > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > > > dbo.InvMove.StockCode inner join inserted on
> > > > > inserted.grn = dbo.trandetails.grn
> > > > >
> > > > >
> > > > > --
> > > > > -Vishal
> > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > news:#4bx4Y#PDHA.2768@tk2msftngp13.phx.gbl...
> > > > > > no I want to insert into table RECEIPTS (this syntax wasn't> > > > > before)
> > > > > > the results of the query
> > > > > >
> > > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > > dbo.TranDetails.OrigReceiptDate
> > > > > > FROM dbo.TranDetailsINNER JOIN
> > > > > > dbo.InvMove ON dbo.TranDetails.StockCode =
> > > > > > dbo.InvMove.StockCode
> > > > > > WHERE . . . the Grn = the Grn of the record that has justtable> the> > then> > > > > inserted
> > > > > > into the TranDetails table
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > > news:OyNGYT#PDHA.3144@tk2msftngp13.phx.gbl...
> > > > > > > are you trying to insert the records into inmove table? if yes> > > > the
> > > > > > > syntax would be.
> > > > > > >
> > > > > > > insert into invmove(col1,col2,col2)
> > > > > > > SELECT a.Supplier, a.Grn,
> > > > > > > a.OrigReceiptDate
> > > > > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > > > > a.stockcode = b.stockcode
> > > > > > > where .....
> > > > > > >
> > > > > > > --
> > > > > > > -Vishal
> > > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > > news:esX$pQ#PDHA.3880@tk2msftngp13.phx.gbl...
> > > > > > > > Thanks but I'm still confused . . . . . :-(
> > > > > > > >
> > > > > > > > where does the InvMove table come into the query?
> > > > > > > > does the inserted temp table just replace the references to> rewrite> > table> > > > > > > TranDetails
> > > > > > > > table?
> > > > > > > >
> > > > > > > > i.e
> > > > > > > >
> > > > > > > > SELECT a.Supplier, a.Grn,
> > > > > > > > a.OrigReceiptDate
> > > > > > > > FROM inserted a INNER JOIN
> > > > > > > > dbo.InvMove b ON a.StockCode =
> > > > > > > > b.StockCode
> > > > > > > >
> > > > > > > >
> > > > > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > > > > news:#g2e5K#PDHA.2244@TK2MSFTNGP11.phx.gbl...
> > > > > > > > > INSERTED table will have same table design as triggering> > > ie
> > > > > > > > > TranDetails (same columnname/datatype) hence you can> mean> > > your
> > > > > > query
> > > > > > > > as
> > > > > > > > >
> > > > > > > > > SELECT a.Supplier, a.Grn,
> > > > > > > > > a.OrigReceiptDate
> > > > > > > > > FROM dbo.TranDetails a INNER JOIN inserted b on
> > > > > > > > > a.stockcode = b.stockcode
> > > > > > > > > where .....
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > -Vishal
> > > > > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > > > > news:e2h7tE#PDHA.1748@TK2MSFTNGP11.phx.gbl...
> > > > > > > > > > Thanks for that but I am not sure understand what you> > .> > > .
> > > > .
> > > > > > ..
> > > > > > > > > >
> > > > > > > > > > Would I need to do something like:
> > > > > > > > > >
> > > > > > > > > > CREATE TRIGGER newrecord
> > > > > > > > > > ON TranDetails
> > > > > > > > > > FOR INSERT
> > > > > > > > > > AS
> > > > > > > > > > SELECT dbo.TranDetails.Supplier, dbo.TranDetails.Grn,
> > > > > > > > > > dbo.TranDetails.OrigReceiptDate
> > > > > > > > > > FROM dbo.TranDetailsINNER JOIN
> > > > > > > > > > dbo.InvMove ON dbo.GrnDetails.StockCode =
> > > > > > > > > > dbo.InvMove.StockCode
> > > > > > > > > > WHERE ???????
> > > > > > > > > >
> > > > > > > > > > where should I be referencing the INSERTED temp table?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > "Vishal Parkar" <vgparkar@hotmail.com> wrote in message
> > > > > > > > > > news:u59y8h9PDHA.2852@tk2msftngp13.phx.gbl...
> > > > > > > > > > > Make use of INSERTED temporary table,the insertedI> can> > > stores
> > > > > > > copies
> > > > > > > > of
> > > > > > > > > > the
> > > > > > > > > > > affected rows during INSERT. this table is visible to
> > > trigger
> > > > > body
> > > > > > > > only.
> > > > > > > > > > ie
> > > > > > > > > > > if you are writing a trigger FOR INSERT operation, you> with> > > > refer
> > > > > > to
> > > > > > > > this
> > > > > > > > > > > table inside the trigger body.
> > > > > > > > > > > See BOL for more information.
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > > -Vishal
> > > > > > > > > > > "Newbie" <noidea@nospam.com> wrote in message
> > > > > > > > > > > news:eJL1Se9PDHA.3016@TK2MSFTNGP10.phx.gbl...
> > > > > > > > > > > > Hi
> > > > > > > > > > > >
> > > > > > > > > > > > I have the following tables TranDetails (3rd Party)> > 4> > > > > > fields
> > > > > > > > > making
> > > > > > > > > > > up
> > > > > > > > > > > > primary key
> > > > > > > > > > > > Supplier char 7
> > > > > > > > > > > > GRN char 7
> > > > > > > > > > > > Journal decimal
> > > > > > > > > > > > JournalEntry decimal
> > > > > > > > > > > > detail1
> > > > > > > > > > > > detail1
> > > > > > > > > > > > detail3
> > > > > > > > > > > >
> > > > > > > > > > > > InvMove
> > > > > > > > > > > > Journal (PK) decimal
> > > > > > > > > > > > JournalEntry (PK) decimal
> > > > > > > > > > > > Stockcode char
> > > > > > > > > > > > Supplier char
> > > > > > > > > > > > Date date
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > GRNDetails
> > > > > > > > > > > > GRN
> > > > > > > > > > > > Supplier
> > > > > > > > > > > > Stockcode
> > > > > > > > > > > > etc
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > when a record is inserted into the TranDetails tablehas> the> > > would
> > > > > > like
> > > > > > > to
> > > > > > > > > > > insert
> > > > > > > > > > > > a record into GRNDetails table based on a query from> > > > > InvMove
> > > > > > > and
> > > > > > > > > > > > TransDetails table.
> > > > > > > > > > > > I want the query to be limited to the record thatcomplete> > just> > > > > been
> > > > > > > > > entered
> > > > > > > > > > > into
> > > > > > > > > > > > the TranDetails table i.e. the query would only ever
> > > return
> > > > > one
> > > > > > > > record
> > > > > > > > > > > >
> > > > > > > > > > > > How would I do this using a trigger? I am a>> >> > > > beginner
> > > > > > > where
> > > > > > > > > > this
> > > > > > > > > > > is
> > > > > > > > > > > > concerned so any help would be greatly appreciated
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Newbie Guest
-
Vishal Parkar #12
Re: trigger question
can you post DDL/some sample records that affects the required condition
(dont give me all the column names only relevant columns). and expected
resultset to be entered into the required table. It seems your query is
getting too longer and i think there are unncessary joins.
-Vishal
Vishal Parkar Guest
-
Newbie #13
Re: trigger question
Record entered into GrnDetail table
Positive receipt:
(PK) Grn 12345
(PK) JournalEntry 20
(PK) Journal 2345
(PK) GrnSource I
QtyReceived 100
Negative receipt
Grn 12345
JournalEntry 21
Journal2346
GrnSource I
Qty Received -100
The other columns go and get some info
At the moment the GRN table is populated . . . . .
1. With a positive receipt
1 record with details as per positive receipt above
2. with a negative receipt
2 records - 1 with details as per positive reciept and 1 with details as
per negative receipt
This means that whenever a negative receipt is performed the GRN table will
have a duplicate record for the positive receipt i.e one that is created at
the time of positive transaction and one that is created at the time of
negative transaction.
Thanks for your continued help
A
"Vishal Parkar" <vgparkar@hotmail.com> wrote in message
news:e2QYHtJQDHA.1624@tk2msftngp13.phx.gbl...> can you post DDL/some sample records that affects the required condition
> (dont give me all the column names only relevant columns). and expected
> resultset to be entered into the required table. It seems your query is
> getting too longer and i think there are unncessary joins.
>
> -Vishal
>
>
Newbie Guest
-
Harbir Singh #14
Trigger Question
Hello again everyone, thanks for all your help
previously. Have another trigger question...
Can a trigger populate fields in another database or is it
functional only in the database that it is created in? I
tried looking in BOL but couldn't find anything on this.
All I found was that it can update/insert fields in
another table in the same db but nothing about other
db's. Thanks in advance for your help.
Harbir Singh Guest
-
Tom Moreau #15
Re: Trigger Question
Yes, you can. You will have to use 3-part (local) of 4-part (remote) naming to access the appropriate objects. Also check out the following for sample code:
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/sql_refintegrity.asp[/url]
--
Tom
---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
[url]www.pinnaclepublishing.com/sql[/url]
"Harbir Singh" <Harbir77@hotmail.com> wrote in message news:43ea01c340ae$499b2f60$a401280a@phx.gbl...
Hello again everyone, thanks for all your help
previously. Have another trigger question...
Can a trigger populate fields in another database or is it
functional only in the database that it is created in? I
tried looking in BOL but couldn't find anything on this.
All I found was that it can update/insert fields in
another table in the same db but nothing about other
db's. Thanks in advance for your help.
Tom Moreau Guest
-
Terry Lee Tucker #16
Trigger Question
Greetings:
Is there any way to pass dynamic data into a trigger function? I think the
answer is no, but just in case...
TIA
--
Work: 1-336-372-6812
Cell: 1-336-363-4719
email: [email]terry@esc1.com[/email]
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Terry Lee Tucker Guest
-
Michael Fuhr #17
Re: Trigger Question
On Wed, Jan 05, 2005 at 02:56:27PM -0500, Terry Lee Tucker wrote:
What do you mean by "dynamic data"? What problem are you trying>
> Is there any way to pass dynamic data into a trigger function? I think the
> answer is no, but just in case...
to solve?
--
Michael Fuhr
[url]http://www.fuhr.org/~mfuhr/[/url]
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [email]majordomo@postgresql.org[/email]
Michael Fuhr Guest
-
Terry Lee Tucker #18
Re: Trigger Question
When I assign a value to a certain column in a table A, I want to be able to
assign a value in table A to table B and then to assign a value in table B to
table C. I was wanting to do this from the trigger level in an AFTER UPDATE
trigger to ensure it gets done. I would like to be able to pass the serial
keys of the associated records in table B and C to the AFTER UPDATE trigger
so I could find the records in tables B and C and perform the updates.
Does that make sense?
Thanks for the reply...
On Wednesday 05 January 2005 03:18 pm, Michael Fuhr saith:--> On Wed, Jan 05, 2005 at 02:56:27PM -0500, Terry Lee Tucker wrote:>> > Is there any way to pass dynamic data into a trigger function? I think
> > the answer is no, but just in case...
> What do you mean by "dynamic data"? What problem are you trying
> to solve?
>
> --
> Michael Fuhr
> [url]http://www.fuhr.org/~mfuhr/[/url]
Work: 1-336-372-6812
Cell: 1-336-363-4719
email: [email]terry@esc1.com[/email]
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
Terry Lee Tucker Guest
-
Michael Fuhr #19
Re: Trigger Question
On Wed, Jan 05, 2005 at 03:25:08PM -0500, Terry Lee Tucker wrote:
What do you mean by "assign a value to a certain column"? Are you> When I assign a value to a certain column in a table A, I want to be able to
> assign a value in table A to table B and then to assign a value in table B to
> table C.
updating an existing record in A? Inserting a new record into A?
Either?
What do you mean by "assign a value in table A to table B"? Do you
want to update an existing record in B with some value from the new
record in A? Or do you want to insert a new record into B based
on the new record in A? Or something else?
Perhaps an example would clarify the requirement: please show what
A, B, and C look like in their "before" state; then show the statement
that should execute the trigger (INSERT, UPDATE, etc.); then describe
what should happen in A, B and C; then show A, B, and C in their
"after" state.
This part isn't clear either. Where are the "serial keys of the> I was wanting to do this from the trigger level in an AFTER UPDATE
> trigger to ensure it gets done. I would like to be able to pass the serial
> keys of the associated records in table B and C to the AFTER UPDATE trigger
> so I could find the records in tables B and C and perform the updates.
associated records in table B and C" being passed from? How are
those records identified? What updates are supposed to be peformed
in the AFTER UPDATE trigger?
As I mentioned above, an example might explain things better.
--
Michael Fuhr
[url]http://www.fuhr.org/~mfuhr/[/url]
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
[url]http://www.postgresql.org/docs/faqs/FAQ.html[/url]
Michael Fuhr Guest
-
Terry Lee Tucker #20
Re: Trigger Question
1) INSERT INTO logs (carr_code, ..., ..., ...) VALUES('ABCDEFG', ..., ...);
logs is table A in my question
2) logs_insert fires (This is a AFTER INSERT trigger)
3) in this trigger, I need to do the following:
update avlds set carr_code = new.carr_code where avlds.recid = ??;
avlds is table B in my question
The questions marks indicate the first piece of data that I want to
dynamically pass to the trigger.
4) in the same trigger:
update tract set order_num = avlds.order_num where tract.recid = ??;
tract is table C in my question
The question marks refer to the second piece of data that I want to pass
dynamically into the trigger.
In other terms, when the user creates a logs record that assigns a truck to a
load, I need to update specific rows in two other tables, avlds, and tract. I
was wanting to do this from the trigger level, but I will need the unique
serial key of each of the existing records in avlds and tract. These two keys
comprise the "dynamic" part of the question. I was just wondering if there is
some way of passing dynamic data into a trigger. I don't believe there is,
but I thought I would ask.
Thanks for the input.
Work: 1-336-372-6812
Cell: 1-336-363-4719
email: [email]terry@esc1.com[/email]
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
Terry Lee Tucker Guest



Reply With Quote

