Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to return 3 strings in delta

Author  Topic 

timrees
Starting Member

1 Post

Posted - 2012-01-27 : 04:22:35
Hi

We have a database containing historical data for 3 strings.

We want to produce a query which will return rows each time 1 of the strings changes (delta mode) and
show the corresponding value of the other 2 strings as they were at that time.

This is using the Wonderware Query software which queries a MS Sql 2005 SP3 database.

The string we want to query is 'UnloadReasonText'.
However, the query we currently have (shown below) will also return row even if 'BatchNr' or 'SAP_Nr'
change, but 'UnloadReason' doesn't.

Is there any way to return only 'UnloadReasonText' in delta and just show the other values at that DateTime?

I assume I need to run two queries within a query? I am new to SQL.

Any help would be appreciated.

Ps. The query we have is as follows:

SET QUOTED_IDENTIFIER OFF
SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime = convert(nvarchar, DateTime, 21), [Furnace_002.BatchNr], [Furnace_001.SAP_Nr], [Furnace_001.UnloadReasonText]
FROM WideHistory
WHERE [Furnace_001.UnloadReasonText] IS NOT NULL
AND wwRetrievalMode = 'Delta'
AND wwVersion = 'Latest'
AND DateTime >= DateAdd(hh,-12,GetDate())
AND DateTime <= GetDate()")

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-27 : 08:24:05
sorry you query and explanation doesnt look simlar. I cant see where you're checking for difference in 'BatchNr' or 'SAP_Nr' values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -