Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL join two conditions 1

Status
Not open for further replies.

skoov

IS-IT--Management
Feb 1, 2007
4
GB
Hi there

I'll try and be as clear as I can, please bear with me :)

I need to perform a select query from a table which will form the data source for a Crystal Report(either SP or view):

Select client number, data field where if client number = 'x' and data_field > 0 then also retrieve the data_field for account 'y' and 'z' if 'y' and 'z' data_field > 0

ie.

if x|client1|data_field > 0

then only return

x|client1|data_field=12
y|client1|data_field=01
z|client1|data_field=03

Not

y|client1|data_field
z|client1|data_field
(ie if account 'x' does not mean the condition then do not retrieve rows for y and z


I have tried doing subqueries and union queries but either the query returns no data or it returns 'y' and 'z' balances regardless of the data in 'x'

I'm not after a finished query solution, just some pointers/clues towards forcing these conditions together.

Thanks in advance!

Chris

 
Thanks Simi

I'll have a read, good info whatever the context.

I'm also wondering If I can select the data into temp tables and derive the data from that.

Cheers

Chris
 
You could but I don't think it is required in this case unless your actual data is more complex then your example.

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top