View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions,microsoft.public.excel
Who be dat?
 
Posts: n/a
Default Error message "formula is too long"

Thanks Duke!! Excellent suggestion. I'll give it a shot.

Chris Smith
"Duke Carey" wrote in message
...
Chris -

Your life would be greatly simplified if you made your query a Stored
Procedure, along the lines of what's shown below, and you could execute it
by
simply using

exec QueryForChris A7

If you are using ADO, "exec QueryForChris" is your command text, A7 is the
value for the parameter, and you need to set the command type to
"adCmdStoredProc"

==================================================
CREATE PROCEDURE QueryForChris
@CurrentTime smalldatetime

AS
DECLARE @startdate datetime
DECLARE @enddate datetime

SET @StartDate = DateAdd(hh, -2, @currenttime)

SET @EndDate = @currenttime

SELECT Top 1 DateTime, Convert(decimal(38,3), Value)

FROM AnalogHistory

WHERE TagName in ('hucTurbidity_001.PV')

AND wwRetrievalMode = 'Cyclic'

AND value IS NOT NULL

AND wwVersion = 'Latest'

AND wwResolution = 1000

AND DateTime @StartDate

AND DateTime <= @EndDate

AND DateTime in

(SELECT Datetime

FROM AnalogHistory

WHERE TagName in ('hucFilterHours_001.PV')

AND value 0.0

AND wwResolution = 1000

AND wwRetrievalMode = 'Cyclic'

AND wwVersion = 'Latest'

AND DateTime @StartDate

AND DateTime <= @EndDate)

ORDER BY Value DESC

GO