0

This is the kind of list i have

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

I have made a stored procedure. The desire is that i want to write something like this

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

The result i desire should then be something like this

Vehicle
Bublebee 
Godzilla

Any tips? This is the current code i have

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
Adnan Hossain
  • 117
  • 2
  • 13
  • what is the issue with your current code – StackUser May 11 '16 at 09:56
  • When i execute this current code. I only get the first of all values, which means i get vehicles wtih ebs7, id = 88 and value = 12345. the other values are not included – Adnan Hossain May 11 '16 at 10:26
  • Recheck your UDF SplitString. Does it return very last value after which there is no Comma? Also, which version of SQL Server are you using?Just an FYI, SQL Server 2016 has an inbuilt function for this, STRING_SPLIT. – Akanksha Singh May 11 '16 at 12:00
  • @AkankshaSingh, There were some small error so now i get both 88 and 89 ID. But the thing is that i want to show vehicles that both contain ID 88 and 89. For the moment i obtain some vehicles that only has ID 88 but not 89 – Adnan Hossain May 11 '16 at 12:23
  • This is somehow a little weird. Could you please share script to create sample data & your UDF script as well? So that we can see if we can reproduce this. – Akanksha Singh May 12 '16 at 09:34

0 Answers0