Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trigger on SELECT

Posted on 2002-03-08
5
Medium Priority
?
256 Views
Last Modified: 2012-08-13
Hello, I am trying to write a trigger which will allow me to intercept a SELECT statement and depending on the WHERE clause in the SELECT statement, I want to output a resultset. For example,

SELECT col FROM A WHERE x = 5;

Ordinarily, it might return

xyz
abc
pqr

Now, if the above query executes against the server, I want to catch it before it executes and return something like

mno

Thus, depending on where clause I wish to manipulate the resultset.

Thanks.
0
Comment
Question by:dbdoshi
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:ruperts
ID: 6851372
can't do that...

Triggers only fire on update/delete/insert.


0
 
LVL 6

Expert Comment

by:curtis591
ID: 6851442
Could you maybe use a stored procedure for something like this instead of a trigger?
0
 
LVL 4

Expert Comment

by:ruperts
ID: 6851462
Well a view is the closest thing I could think of..
0
 

Author Comment

by:dbdoshi
ID: 6851720
Yes, anything will go. View or Stored Proc? Can somebody give a little example.
0
 
LVL 6

Accepted Solution

by:
curtis591 earned 300 total points
ID: 6851742
I am not really sure what you are looking for but something like this may work


create procedure test @param1 varchar(100) as
declare @return varchar(10)
if @param1 = 'ME'
 set @return = 'YES'
else
  if @param1 = 'YOU'
    set @return = 'NO'
else
  set @return = 'NOT SURE'

select @return

 
 
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question