[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

howto: I need trigger with parameter

Aykut Canturk

3/27/2007 8:07:00 PM

I need to write a trigger that updates every record inserted to database.
this trigger will update only one field lets say 'branchofficename' field in
table. But in my VB application, that uses that database and that table, I
need to declare a database-wide parameter, lets'say Branch_Office_Name. so
it this sould work like that way:

In newyork office my application should do this:

On starting of my Vb application: set database.Branch_Office_Name =
"NewYork"
and trigger should do: update every record inserted, setbranchofficename =
'NewYork'

on oregon office, same applicatipn and same triggers. but parameter will
change:

On starting of my Vb application: set database.Branch_Office_Name =
"Oregon"
and trigger should do: update every record inserted, setbranchofficename =
'Oregon'

My aim is: I need to seperate records of each branch office, but also, all
of these records must have stored in one central database. (don't ask why,
thats customer choice)
Any idea howto do this ? I searched the net to find a kind of global
variable decleration in sql server and ADO but couldn't reach any
solution...

any help please ?


2 Answers

Tibor Karaszi

3/27/2007 8:14:00 PM

0

> I searched the net to find a kind of global variable decleration in sql server

SET CONTEXT_INFO?

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/d...
http://www.solidqualitylea...


"Aykut Canturk" <aykut.canturk@karina-mira.com> wrote in message
news:%23ijXDuKcHHA.4616@TK2MSFTNGP03.phx.gbl...
>I need to write a trigger that updates every record inserted to database. this trigger will update
>only one field lets say 'branchofficename' field in table. But in my VB application, that uses that
>database and that table, I need to declare a database-wide parameter, lets'say Branch_Office_Name.
>so it this sould work like that way:
>
> In newyork office my application should do this:
>
> On starting of my Vb application: set database.Branch_Office_Name = "NewYork"
> and trigger should do: update every record inserted, setbranchofficename = 'NewYork'
>
> on oregon office, same applicatipn and same triggers. but parameter will change:
>
> On starting of my Vb application: set database.Branch_Office_Name = "Oregon"
> and trigger should do: update every record inserted, setbranchofficename = 'Oregon'
>
> My aim is: I need to seperate records of each branch office, but also, all of these records must
> have stored in one central database. (don't ask why, thats customer choice)
> Any idea howto do this ? I searched the net to find a kind of global variable decleration in sql
> server and ADO but couldn't reach any solution...
>
> any help please ?
>
>


David Portas

3/27/2007 9:47:00 PM

0

On 27 Mar, 21:07, "Aykut Canturk" <aykut.cant...@karina-mira.com>
wrote:
> I need to write a trigger that updates every record inserted to database.
> this trigger will update only one field lets say 'branchofficename' field in
> table. But in my VB application, that uses that database and that table, I
> need to declare a database-wide parameter, lets'say Branch_Office_Name. so
> it this sould work like that way:
>
> In newyork office my application should do this:
>
> On starting of my Vb application: set database.Branch_Office_Name =
> "NewYork"
> and trigger should do: update every record inserted, setbranchofficename =
> 'NewYork'
>
> on oregon office, same applicatipn and same triggers. but parameter will
> change:
>
> On starting of my Vb application: set database.Branch_Office_Name =
> "Oregon"
> and trigger should do: update every record inserted, setbranchofficename =
> 'Oregon'
>
> My aim is: I need to seperate records of each branch office, but also, all
> of these records must have stored in one central database. (don't ask why,
> thats customer choice)
> Any idea howto do this ? I searched the net to find a kind of global
> variable decleration in sql server and ADO but couldn't reach any
> solution...
>


Any reason why you can't use a parameterized procedure instead of a
trigger?

If you must use a trigger then you could create a function to return
your global parameter.

CREATE FUNCTION dbo.BranchName()
RETURNS VARCHAR(50)
AS
BEGIN
RETURN (SELECT BranchName FROM SomeTable);
END

Then assign it to a local variable in the trigger:

SET @Branch = dbo.BranchName();

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/librar...(en-US,SQL.90).aspx
--