Well Not sure if this helps but,Using your example data and a function to split the String data.This gets the data your looking for, but it still needs to be pivoted to display it the way you asked for. But this is a little past my expertise at the moment. In SQL 2005 I am sure this could be done with the new PIVOT function.Anyway here is what i was ale to cobble together. See if this is close.Create Table #Example( Date_Time DateTime, TagName VarChar(75), SensorValue decimal(18, 12), EU Varchar(5));Insert Into #Example Values('2010-12-14 20:05:19.000', 'BacNet1.FCB.AnalogInput_3000812_OA-T.PresentValue', 14.503324508667,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000812_OA-T.PresentValue',14.503324508667,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000873_PH-T.PresentValue',76.4392013549805,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000881_HWCE-T.PresentValue',116.347183227539,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000882_HWCL-T.PresentValue',114.867370605469,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000887_DA-T.PresentValue',101.547485351563,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000895_EAHR-T.PresentValue',71.9544372558594,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000902_MA-T.PresentValue',79.6642150878906,Null);Insert Into #Example Values('2010-12-14 20:05:19.000','BacNet1.FCB.AnalogInput_3000906_RA-T.PresentValue',79.0135269165039,Null);Insert Into #Example Values('2010-12-14 20:05:20.000','BacNet1.FCB.AnalogInput_3001007_GLYR-T.PresentValue',37.868766784668,Null);Insert Into #Example Values('2010-12-14 20:05:20.000','BacNet1.FCB.AnalogInput_3001008_GLYS-T.PresentValue',37.4429359436035,Null);Insert Into #Example Values('2010-12-14 20:05:20.000','BacNet1.FCB.AnalogInput_3001009_INFLOOR-T.PresentValue',103.629348754883,Null);Update #Example Set TagName = (Select Items From dbo.fn_Split(TagName,'_') Where Items In ('GLYR-T.PresentValue', 'GLYS-T.PresentValue', 'GLYS-T.PresentValue') )--Select * From #Example Select Distinct(Date_Time), TagName, SensorValue From #Example Where TagName is not null group by Date_Time, TagName, SensorValueDrop Table #ExampleAnd the function I used. (easily found vis Google.)Create FUNCTION [dbo].[fn_Split](@String varchar(4000), @Delimiter char(1))RETURNS @Results TABLE (ID int, Items nvarchar(4000))ASBEGINDECLARE @INDEX INTDECLARE @SLICE nvarchar(4000)DECLARE @ID intSELECT @INDEX = 1, @ID = 1WHILE @INDEX !=0BEGIN-- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTERSELECT @INDEX = CHARINDEX(@Delimiter,@String)-- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLEIF @INDEX !=0SELECT @SLICE = LEFT(@String,@INDEX - 1)ELSESELECT @SLICE = @String-- PUT THE ITEM INTO THE RESULTS SETINSERT INTO @Results(ID, Items) VALUES(@ID, @SLICE)SELECT @ID = @ID + 1-- CHOP THE ITEM REMOVED OFF THE MAIN STRINGSELECT @String = RIGHT(@String,LEN(@String) - @INDEX)-- BREAK OUT IF WE ARE DONEIF LEN(@String) = 0 BREAKENDReturnEND
Thank You,John