I am having trouble creating a query. I have the following tables (simplified):
table1:
doc_no line country
12 1 NL
12 2 US
12 ... ...
12 m FR
13 1 NL
13 ... ...
13 n GR
... ... ...
table2:
doc_no user_doc
12 123456
13 654321
I need to create a query that joins both tables on doc_no
and returns the following result set(s):
user_doc country-1 country-2 country-... country-m
123456 NL US ... FR
user_doc country-1 country-... country-n
654321 NL ... GR
user_doc country-...
... ...
There are no set values for m, n or the number of doc_no's in both tables. In the end, the resultset will be limited be the interval in which the query will run (likely to be 30 or 60 seconds) so the result set can be 10's of doc_no's. Most likely is that the result set will be ranging from 1 to 5 user_doc's, but more is possible.
The database allows data-extraction only, so I cannot create temp tables, stored procedures, views etc. only select-type queries using local variables etc using T-SQL.
I am completely lost for solutions, so any suggestion would be wonderful
Thx,
Martin