Hi to all and thanks for your time.
I'm getting cracy since last week in order to let this open query work. The problem I think is regarding this fuck*** quotation marks.
declare @TSQL nvarchar(max)
set @TSQL =
'SELECT * FROM OPENQUERY(INSQL,''
SELECT DateTime = convert(nvarchar, DateTime, 21), [Valve_Log_009.TareWeight], [Valve_Log_009.FillWeight],'
+ ' [Valve_Log_009.FineWeight], [Valve_Log_009.ActualTail], [Valve_Log_009.FillTime], [Valve_Log_009.wStatus]'
+ ' FROM WideHistory WHERE wwRetrievalMode = ''''Delta'''' AND wwQualityRule = ''''Good''''
AND wwVersion = ''''Latest'''' AND DateTime >= ''''' + convert(nvarchar, @StartDate,21) + ''''' AND DateTime <= ''''' + convert(nvarchar,@EndDate, 21) + ''''')'
The result is:
Unclosed quotation mark after the character string '
If I add 2 single quotation marks at the end it won't work.
I started from this query, it works but without parameters, so I must convert it in order to pass valve number and timeframe:
set @TSQL4 = '
SELECT * FROM OPENQUERY(INSQL,''
SELECT DateTime = convert(nvarchar, DateTime, 21), [Valve_Log_009.TareWeight], [Valve_Log_009.FillWeight],'
+ ' [Valve_Log_009.FineWeight], [Valve_Log_009.ActualTail], [Valve_Log_009.FillTime], [Valve_Log_009.wStatus]'
+ ' FROM WideHistory WHERE wwRetrievalMode = ''''Delta'''' AND wwQualityRule = ''''Good''''
AND wwVersion = ''''Latest'''' AND DateTime >= DateAdd(mi,-60,GetDate()) AND DateTime <= GetDate()'')'
Any help will be very appreciated.