通过具有多个输入参数来获取所请求的项目

时间:2016-05-11 09:43:12

标签: sql sql-server stored-procedures aggregate-functions mss

这是我有的那种清单

Vehicle           ECU       ID           Value
Bumblebee         EBS7      88           12345
Bumblebee         EBS7      89           96325
Bumblebee         EBS7      90           14725
Bumblebee         TMS1      89           12347  
Godzilla          TMS1      88           15963 
Godzilla          TMS1      89           12347
Godzilla          EBS7      88           12345
Godzilla          EBS7      89           96325
Prime             EBS7      88           25899
Prime             EBS7      89           12347

我已经制作了一个存储过程。我希望能写出像这样的东西

Exec spVehicles 'EBS7', '88,89', '12345,96325'

我想要的结果应该是这样的

Vehicle
Bublebee 
Godzilla

任何提示? 这是我目前的代码

alter procedure spGetLatest 
@ECU nvarchar(20),
@Identifier nvarchar(20),
@Value nvarchar(20)
as
Begin
Select Name,ECU, Identifier, Value, Max(Filetime) as "latestfile" from dbo.view_1
group by Name, ECU, Identifier, Value
Having ECU IN (Select Item from [dbo].[SplitString](@ECU,',')) and 

Identifier IN (SELECT Item  FROM [dbo].[SplitString]( @Identifier, ',' ) ) and Value IN (Select Item FROM [dbo].[SplitString](@Value,','))  
ORDER BY
    MAX(Name) ASC
End

0 个答案:

没有答案