I see a lot of similar questions, but almost all of them wind up grouping results as column names (Column names based on results), mine is a more simple list. I don't care if it uses dynamic SQL or not (I'd think it has to).
Please don't tell me I need to restructure the tables, I'm working from a legacy system and don't have that option.
Basically, I just need a list of all valid table "B" entries that match a given record from table "A", in a row.
I don't have any code sample yet, because I'm not seeing a way to set this up correctly.
Table: Customer c CustID Name 1 Bill Smith 2 Jim Jones 3 Mary Adams 4 Wendy Williams Table: Debt d CustID Creditor Balance 1 ABC Loans 245 1 Citibank 815 2 Soprano Financial 74000 3 Citibank 24 3 Soprano Financial 93000 3 Wells Fargo 275 3 Midwestern S&L 2500 4 ABC Loans 1500 4 Fred's Payday Loan 1000 Desired Output: Name Cred1 Bal1 Cred2 Bal2 Cred3 Bal3 Cred4 Bal4 Bill Smith ABC Loans 245 Citibank 815 (NULL) (NULL) (NULL) (NULL) Jim Jones Soprano Financial 74000 (NULL) (NULL) (NULL) (NULL) (NULL) (NULL) Mary Adams Citibank 24 Soprano Finanacial 93000 Wells Fargo 275 Midwestern S&L 2500 Wendy Williams ABC Loans 1500 Fred's Payday Loan 1000 (NULL) (NULL) (NULL) (NULL)
Basically, I probably have to collect some kind of count of the most number of records for any specific "CustomerID", and define the output columns based on that. If this has already been answered, feel free to link and close this out, I did not see this specific scenario when I did my search.