maxgohan
maxgohan

Reputation: 39

looping dynamic sql statement?

I am trying to create some sort of SQL statement that I can execute via SQuirrel SQL client, connected to a IBM DB2 server

I have 2 queries, the 2nd query will use information output by the first query.

Select num, date(timestamp) date from myTable
where col1 = x and col2 = y

this query will give me 2 columns named num and date

I want the following query to run for each record output by the 1st query

select summary from myTable
where col3 = query1.num and col4 >= query1.date and col5 = z

how can I accomplish this in sql only?

Upvotes: 0

Views: 90

Answers (1)

Siyual
Siyual

Reputation: 16917

You can do this in one query:

Select  M2.Summary
From    MyTable     M1
Join    MyTable     M2  On  M2.Col3 = M1.Num
                        And M2.Col4 >= Date(M1.Timestamp)
Where   M1.Col1 = X
And     M1.Col2 = Y
And     M2.Col5 = Z

Upvotes: 1

Related Questions