Mark Ellul
Mark Ellul

Reputation: 1906

Using a SELECT Statement in the WHERE IN Clause i.e. WHERE blah in (SELECT b...)

I am trying to do some complex pivot query... and I need to do a select in the IN Clause...

Example of the Pivot

Looking at the Example in the above link, you can see they use the employee ids explicitly in their pivot. I would like to be able to do select instead of specifying the employee ids.

The only way I can think of doing it now, is by creating my pivot query in a string and using manipulation in a Stored Prodcedure to build the employee ids into a string, insert that into my PIVOT clause, and execute the resulting SQL....

Anyone think of a better way to do this?

Upvotes: 1

Views: 499

Answers (1)

user53794
user53794

Reputation: 3830

You pretty much have to use dynamic SQL when construction pivot queries when the pivot column contents cannot be hard coded.

Upvotes: 1

Related Questions