• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Trigger on SELECT

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
dbdoshi
Asked:
dbdoshi
  • 2
  • 2
1 Solution
 
rupertsCommented:
can't do that...

Triggers only fire on update/delete/insert.


0
 
curtis591Commented:
Could you maybe use a stored procedure for something like this instead of a trigger?
0
 
rupertsCommented:
Well a view is the closest thing I could think of..
0
 
dbdoshiAuthor Commented:
Yes, anything will go. View or Stored Proc? Can somebody give a little example.
0
 
curtis591Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now