79177463

Date: 2024-11-11 11:31:01
Score: 7 🚩
Natty: 4
Report link

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.

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (1): appreciated
  • Blacklisted phrase (1): Any help
  • Blacklisted phrase (2): fuck
  • RegEx Blacklisted phrase (3): Any help will be very appreciated
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: desknotes