动态 SQL WHILE 导致管理工作室的结果窗格中出现许多窗口
Dynamic SQL WHILE leads to many winodws in result pane in management studio
我有这样的疑问:
declare @ProjectID int
declare @Keyword nvarchar(255)
declare @SEID int
select distinct
@ProjectID=Project_Id,
@Keyword=keyword,
@SEID=SE_Id
from [RL].[SearchMetrics_ProjectKeyword] --it returns 120 rows
while @ProjectID is not null
begin
SELECT *
FROM Table 1
where ID = @ProjectID
and Keyword = @Keyword
and SEID = @SEID
end
然后我在结果窗格中有 120 个结果 windows。但我想把所有的结果都集中在一个 window
I have 120 result windows in result pane
如果你 运行 120 select 语句
I would like to have all the resualts only in one window
将其作为普通连接执行:
Select * from
(
select distinct Project_Id, keyword, SE_Id from [RL].[SearchMetrics_ProjectKeyword]
) f
INNER JOIN
Table1 t
ON
t.ID=F.Project_ID and
t.Keyword= f.Keyword and
t.SEID=f.SE_ID
您的查询有一些语法错误,所以我不得不猜测 Table1 的名称。此查询可能需要一些小的修复
我有这样的疑问:
declare @ProjectID int
declare @Keyword nvarchar(255)
declare @SEID int
select distinct
@ProjectID=Project_Id,
@Keyword=keyword,
@SEID=SE_Id
from [RL].[SearchMetrics_ProjectKeyword] --it returns 120 rows
while @ProjectID is not null
begin
SELECT *
FROM Table 1
where ID = @ProjectID
and Keyword = @Keyword
and SEID = @SEID
end
然后我在结果窗格中有 120 个结果 windows。但我想把所有的结果都集中在一个 window
I have 120 result windows in result pane
如果你 运行 120 select 语句
I would like to have all the resualts only in one window
将其作为普通连接执行:
Select * from
(
select distinct Project_Id, keyword, SE_Id from [RL].[SearchMetrics_ProjectKeyword]
) f
INNER JOIN
Table1 t
ON
t.ID=F.Project_ID and
t.Keyword= f.Keyword and
t.SEID=f.SE_ID
您的查询有一些语法错误,所以我不得不猜测 Table1 的名称。此查询可能需要一些小的修复