[SQL] Query execution based on a condition

2012-12-29 Thread JORGE MALDONADO
I have a query similar to the one shown below but, depending on the value
of a field, only the first SELECT statement shoud execute and the other 3
should be ignored. Is there a way to achieve this situation?

SELECT fields FROM tblTable WHERE condition
UNION
SELECT fields FROM tblTable WHERE condition
UNION
SELECT fields FROM tblTable WHERE condition
UNION
SELECT fields FROM tblTable WHERE condition

Respectfully,
Jorge Maldonado


Re: [SQL] Query execution based on a condition

2012-12-29 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org]
On Behalf Of JORGE MALDONADO
Sent: Saturday, December 29, 2012 2:06 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] Query execution based on a condition

 

I have a query similar to the one shown below but, depending on the value of
a field, only the first SELECT statement shoud execute and the other 3
should be ignored. Is there a way to achieve this situation?

 

SELECT fields FROM tblTable WHERE condition

UNION

SELECT fields FROM tblTable WHERE condition

UNION

SELECT fields FROM tblTable WHERE condition

UNION

SELECT fields FROM tblTable WHERE condition

 

Respectfully,

Jorge Maldonado

 

 

Not using pure SQL.  pl/pgsql provides you access to conditionals and flow
control so you should be able to create a function to do precisely what you
need.

 

David J.

 



Re: [SQL] Query execution based on a condition

2012-12-29 Thread msi77
Change the conditions of other 3 queries, so those shall give empty row sets 
depending on your value.

29.12.2012, 23:06, "JORGE MALDONADO" :
> I have a query similar to the one shown below but, depending on the value of 
> a field, only the first SELECT statement shoud execute and the other 3 should 
> be ignored. Is there a way to achieve this situation?
>
> SELECT fields FROM tblTable WHERE condition
> UNION
>
> SELECT fields FROM tblTable WHERE condition
>
> UNION
>
> SELECT fields FROM tblTable WHERE condition
> UNION
>
> SELECT fields FROM tblTable WHERE condition
>
> Respectfully,
> Jorge Maldonado


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Query execution based on a condition

2012-12-29 Thread Adrian Klaver

On 12/29/2012 11:05 AM, JORGE MALDONADO wrote:

I have a query similar to the one shown below but, depending on the
value of a field, only the first SELECT statement shoud execute and the
other 3 should be ignored. Is there a way to achieve this situation?


Probably so, but is hard to be specific without more information. In a 
particular the condition/field being tested and values being tested for.



Respectfully,
Jorge Maldonado



--
Adrian Klaver
adrian.kla...@gmail.com


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql