Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Statement in Trigger

Author  Topic 

tvb2727
Starting Member

35 Posts

Posted - 2010-10-16 : 20:46:12
I need to pull data from the table to use in a trigger. How can I run an select statement in a trigger and put the data in a variable?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-16 : 23:37:11
The T-SQL is the same as it would be if you weren't using a trigger, except maybe you'd use the deleted or inserted trigger tables.

What exactly are you trying to do? Can you show us a data example of what the DML is doing and then what you want to the trigger to do?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 02:37:15
please keep in mind that select might return more than single value in which case you wont be able to store it in a variable. You can never assume that trigger will only process one record at a time. So you may be better off using a table variable instead of normal variable

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 02:37:47
please keep in mind that select might return more than single value in which case you wont be able to store it in a variable. You can never assume that trigger will only process one record at a time. So you may be better off using a table variable instead of normal variable

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -