本文介绍了如何通过where子句过滤execute(@query)的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
执行(@query)
问题是@query的列数是动态的,未知,因为查询是PIVOT的结果: TSQL从两个表创建动态报告,一个表包含标题,另一个表,数据
我想得到的结果是这样的:
select * from execute (@query)where column(1)='something'
感谢您的帮助。 / p>
解决方案
set @query = N'select * from('+ @query + N' )t where [col1] =''something''';
exec(@query)
您可以使用未转义的表格列出这个列的名字,然后用col1代替。
I'd like to know how to filter (put where clause) in the result of a dynamic query like this:
execute(@query)
The problem is the number of columns of @query is dynamic and titles are unknown because the query is the result of a PIVOT:
TSQL creating a dynamic report from two tables, one table is holds the headers, other one, data
The result I want to get is something like this:
select * from execute(@query) where column(1) = 'something'
Thanks for your help in advance.
解决方案
set @query = N'select * from (' + @query + N') t where [col1] = ''something''';
exec (@query)
You could use the unpivoted table to figure out what the name of the column would be, and use this in place of col1.
这篇关于如何通过where子句过滤execute(@query)的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!