Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

If-Then in SQL

1 view
Skip to first unread message

Andy Turiansky [TeamSybase]

unread,
Jul 17, 2003, 12:34:27 PM7/17/03
to
SELECT COLUMNA
FROM TABLEA
WHERE
somevalue = (SELECT COLUMNB FROM TABLEB)

or you can script this in a stored procedure

On Thu, 17 Jul 2003 12:13:16 -0400,
in powersoft.public.powerbuilder.database
Tom S <po...@messageboard.com> wrote:
>First the specs: Win 2K Pro
> P.B. 7.0.3 Build 10180
>
>I am trying to write an SQL statement that runs a SELECT based upon the
>results of another SELECT. The attached file is the code I've written.
>Everytime I run it though I get an error saying "Host variable may not be
>used within a batch". First, I dont' know what that means (although I think
>it may have something to do with the use of a retrevial argument in the
>first SELECT). And second, how can I fix this so that it does what I want?
>Thanks for the help.
>
>Tom
>
>

- - -
Andy [TeamSybase]

Techwave 2003 - http://www.sybase.com/techwave2003
International Sybase User Group (ISUG) - http://www.isug.com
CodeXchange - http://powerbuilder.codeXchange.sybase.com/


Tom S

unread,
Jul 17, 2003, 1:11:43 PM7/17/03
to
But the problem is that the two SELECT statements that are run (not the
imbedded one) have different values for what they select as well as a
different WHERE clause because the second has nothing in the "invoices"
table. Any other suggestions?

"Andy Turiansky [TeamSybase]" <aturi...@comcast.net> wrote in message
news:u4LXLFITDHA.342@forums-2-dub...

Scott Morris

unread,
Jul 17, 2003, 2:55:04 PM7/17/03
to
A general technique - i'll leave the details to you

select [data based on invoice existence]
union
select [client data with hard coded amount]

If you need to know the source of a particular row (i.e., did it come from
the first select or the second), include a hardcoded column that
differentiates. You should also do this so you can sort the results,
forcing the row from the 2nd query to come last. This way, you always get
at least one row. If you get more than one row, you can safely ignore the
last one.

"Tom S" <po...@messageboard.com> wrote in message
news:%23PynHfITDHA.344@forums-2-dub...

0 new messages