I have two select queries that I need to combine….
SELECT [DatapointID]
,[AssetID]
,[DatapointID]
,[SourceTag]
,'-' + [TimeStep] + [TimeStepValue] AS TimeStep
,[DataRetrievalInterval] + [DataRetrievalIntervalValue] AS [RetInterval]
,NULL AS DatapointDate
,NULL AS DatapointValue
,0 As DataFlagID
,DateADD(-1, d @SearchDateEnd) + @SearchTimeEnd DateDataGrabbed
,GetDate() DateTimeAddedtoDB
FROM [dbo].[tblTSS_Assets_Datapoints]
Where AssetID = 204
Select DatapointDate, SUM(DataPointValue) as DataPointValue From @temp
GROUP BY DatapointDate
ORDER BY DatapointDate
The first select query is what I want the end result to be however instead of NULL As the DatapointDate and DatapointValue I want the values from the @temp
How can I do this?
A join will combine the values from the two tables. In this case, there is not an obvious join key, so you would have a cross join:
This, however, will multiply the number of rows, with one for each date. Do you have a specific rule for choosing one of the rows?