0
declare @RelevantMachines Table (MachineId int)

Select MachineId, ClusterId, MachineGuid, MachineName, RegisteredDate, MachineDetail, LastServiceCall, MachineType as MachineTypeId, ProductSetId
From PatchHub.Machine
Where ClusterId = @ClusterId

我希望能够将 select 语句作为结果集返回,同时使用所有返回的行 MachineId 值填充表变量,这是在 sql server 2008 中。如何在不运行 select 语句的情况下实现这一点两次?

4

1 回答 1

1

我不相信你可以在一个 SELECT 中做到这一点,我认为下一个最好的事情是这样的:

declare @result table (
MachineId int, 
ClusterId int, 
MachineGuid guid, 
MachineName varchar(100), 
RegisteredDate datetime, 
MachineDetail varchar(1000), 
LastServiceCall int, 
MachineType int, 
ProductSetId int)

Select MachineId, ClusterId, MachineGuid, MachineName, RegisteredDate, MachineDetail, LastServiceCall, MachineType as MachineTypeId, ProductSetId
into @result
From PatchHub.Machine
Where ClusterId = @ClusterId

select * from @result

/* use @result table */
于 2012-11-08T12:21:46.427 回答