473,804 Members | 3,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Current Identity(Proced ure)

Hi everyone,
How can I retrieve the current identity used in a procedure from a
trigger.

What I am trying to do is:

The procedure takes a @username (nvarchar) as a parameter, and the
procedure identifies the @username's identity and tries to delete the
identity's row. An Instead Of trigger fires, and updates the specific
row.

But how can the trigger identify the targeted row?
Which built-in function can I use?

Thanks

gardmt
Jul 20 '05 #1
3 7899

"Gard T?nnesland" <ga*********@ho tmail.com> wrote in message
news:3d******** *************** ***@posting.goo gle.com...
Hi everyone,
How can I retrieve the current identity used in a procedure from a
trigger.

What I am trying to do is:

The procedure takes a @username (nvarchar) as a parameter, and the
procedure identifies the @username's identity and tries to delete the
identity's row. An Instead Of trigger fires, and updates the specific
row.

But how can the trigger identify the targeted row?
Which built-in function can I use?

Thanks

gardmt


You can use @@IDENTITY - see Books Online. Assuming you have MSSQL 2000,
there are also SCOPE_IDENTITY( ), and IDENT_CURRENT() , but the functionality
is slightly different in each case. To get the new value while in the stored
procedure you would use SCOPE_IDENTITY( ) instead.

Simon
Jul 20 '05 #2
[posted and mailed, please reply in news]

Gard T?nnesland (ga*********@ho tmail.com) writes:
How can I retrieve the current identity used in a procedure from a
trigger.

What I am trying to do is:

The procedure takes a @username (nvarchar) as a parameter, and the
procedure identifies the @username's identity and tries to delete the
identity's row. An Instead Of trigger fires, and updates the specific
row.

But how can the trigger identify the targeted row?
Which built-in function can I use?


In a trigger, both INSTEAD OF and AFTER triggers, you have access to
the virtual tables "inserted" and "deleted". They hold the rows that
were inserted and deleted. (So in an INSERT trigger you have only
data in "inserted" and in a DELETE trigger only in "deleted", and
in UPDATE trigger, you have data in both.)

Note that since a trigger fires once per statment, you should write
the trigger so that it handles this situation. For instance:

CREATE TRIGGER Gard_tri ON tbl INSTEAD OF DELETE AS
UPDATE tbl
SET active = 0
FROM tbl t
JOIN deleted d ON t.keycol = d.keycol
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
Erland Sommarskog <so****@algonet .se> wrote in message news:<Xn******* ************@12 7.0.0.1>...
[posted and mailed, please reply in news]

Gard T?nnesland (ga*********@ho tmail.com) writes:
How can I retrieve the current identity used in a procedure from a
trigger.

What I am trying to do is:

The procedure takes a @username (nvarchar) as a parameter, and the
procedure identifies the @username's identity and tries to delete the
identity's row. An Instead Of trigger fires, and updates the specific
row.

But how can the trigger identify the targeted row?
Which built-in function can I use?


In a trigger, both INSTEAD OF and AFTER triggers, you have access to
the virtual tables "inserted" and "deleted". They hold the rows that
were inserted and deleted. (So in an INSERT trigger you have only
data in "inserted" and in a DELETE trigger only in "deleted", and
in UPDATE trigger, you have data in both.)

Note that since a trigger fires once per statment, you should write
the trigger so that it handles this situation. For instance:

CREATE TRIGGER Gard_tri ON tbl INSTEAD OF DELETE AS
UPDATE tbl
SET active = 0
FROM tbl t
JOIN deleted d ON t.keycol = d.keycol


Thanks for your great reply. Takker og bukker (sjefen blir fornøyd).

Gard Tønnesland
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
613
by: Norton | last post by:
Dear All, Does anyone know hoe to get the current procedure name in Vb.Net ? Example Private Function TestingMe() as string Return thisProcedureName End Function and the function can return "TestingMe"
1
2394
by: Tony Wilkinson | last post by:
Hi, Does anyone know if it is possible to get the current procedure name from any function or code please. I have had many occassions to need this but have not been able to find a way of doing it. One example of the use I want to put it to is to create a generic error message function that can be called by passing the calling
5
2996
by: Lyn | last post by:
Is there any way of determining in VBA the name and arguments of the currently executed procedure? To assist in debugging, I would like to be able to trace the procedures as they are executed. Then, when it crashes with Access's usual unhelpful error messages, at least I will be able to determine in which procedure it happened. What I had in mind was something like this, inserted as the first statement in every procedure during...
1
3568
by: windandwaves | last post by:
Hi Folks In Google, I read: Jonathan Roenberg Mar 5 2001, 8:35 am Is there a way in VBA to find the name of the current procedure at run time? This would be very helpful for some error checking I'm doing in my
6
1263
by: Tor Inge Rislaa | last post by:
Finding current Procedure I want to write errors to a log-file, where the error log contain the description of where the error occurred and what kind of error it was. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click On Error GoTo errHandler
2
1253
by: Luqman | last post by:
How can I display only current procedure in VB.Net 2005, like Vb-6, I mean Procedure View and full Module View in VB-6 ? Best Regards, Luqman
6
2604
by: Ronchese | last post by:
Hello, is there any way to get the name of the current running procedure? For example: Public Sub Test( ) 'do something '...
1
1459
by: Kevin Wilcox | last post by:
In response to queries about getting the name of the current procedure for error handling etc, respondents have recommended using e.g. MZ Tools. I've downloaded this, but have a quick query before I install; Will this become an add-in into my copy of access? Actually, easier if I explain my concern instead: - I work in a massive organisation with levels of bureacracy that could thwart angels. I'm not supposed to install downloaded...
5
3844
by: NJonge01 | last post by:
Is there a way to dynamically refer to the name of the current procedure? I'd like to add a dynamic reference to the current procedure in my logging procedure. I've googled around and found nothing (just another guy asking the same question on the utteraccess board, but with no answer). TIA for any help!
0
10571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.