Solved

Trigger on SELECT

Posted on 2002-03-08
5
201 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 75 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now