我有这个存储过程生成的结果。
我想将这些结果与另一个表中的数据连接起来。我已经看到了创建临时表并将其插入其中的各种示例,但是,这并不理想,因为存储过程会返回许多可能会更改的动态列。有没有办法动态加入它们?
示例场景:
存储过程返回:
EXEC uspGetProductCategories
products_id | products_model | Leather Seats | Heated Seats | Tapedeck | Heater | Hybrid | Sunroof | Cruise Control
===================================================================================================================
100 | Saturn Vue | N | N | Y | N | N | N | N
200 | Toyota Pruis | Y | N | N | Y | Y | N | N
300 | Ford Focus | N | N | N | Y | N | N | Y
我想用一个 SQL 查询加入它,该查询会生成如下内容:
SELECT * FROM Products_Detail
products_id | manufacturer | purchaser | pay_type
=================================================
100 | GM | GREG | P
200 | TOYT | SAM | P
300 | FORD | GREG | L
换句话说...
有没有一种无痛的方法可以做到这一点?这是我想要实现的一些伪代码(尽管我知道这不起作用):
SELECT pd.*, sp.* FROM Products_Detail pd
LEFT JOIN uspGetProductCategories sp ON pd.product_id = sp.product_id
同样,我知道你不能这样做,但希望它描述了我正在寻找的逻辑。
示例所需的输出
products_id | manufacturer | purchaser | pay_type | products_model | Leather Seats | Heated Seats | Tapedeck | Heater | Hybrid | Sunroof | Cruise Control
=========================================================================================================================================================
100 | GM | GREG | P | Saturn Vue | N | N | Y | N | N | N | N
200 | TOYT | SAM | P | Toyota Pruis | Y | N | N | Y | Y | N | N
300 | FORD | GREG | L | Ford Focus | N | N | N | Y | N | N | Y