Monday, March 19, 2012

drop out of stored procedure when found some data

Hi
I have a stored procedure which takes a while to run and returns some
data. I want to make
another version that just says is there some data to look at (boolean,
yes no). This should
run as quickly as possible so as soon as it finds theres any data to
look at it stops. Is
there any general way of doing this?
This has to work in oracle and sqlserver 2000.
Can this be done in SQL. I'm afraid I know very little about SQL so I
just don't know if its even possible?
thanks
fshard wrote:
> Hi
> I have a stored procedure which takes a while to run and returns some
> data. I want to make
> another version that just says is there some data to look at (boolean,
> yes no). This should
> run as quickly as possible so as soon as it finds theres any data to
> look at it stops. Is
> there any general way of doing this?
> This has to work in oracle and sqlserver 2000.
> Can this be done in SQL. I'm afraid I know very little about SQL so I
> just don't know if its even possible?
> thanks
> f
Use EXISTS:
IF EXISTS (SELECT ... /* something */)
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||> IF EXISTS (SELECT ... /* something */)
> --
> David Portas, SQL Server MVP
thanks for that, nice simple answer.

No comments:

Post a Comment