Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trigger on SELECT

Posted on 2002-03-08
5
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

715 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