Solved

Trigger on SELECT

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

808 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