Syntax issues with SQL

Hey everyone,

I've been trying to figure out how to deal with this syntax issue i'm having.
I'm using a template node to design my query and then pass it to an mssqlplus node.

This is the query (in the template node)

IF EXISTS
    (SELECT 1 FROM c5_total_daily WHERE denom='{{denomName}}' AND CONVERT(DATE, endtime) = CONVERT(DATE, getdate()))
    BEGIN
    UPDATE c5_total_daily
    SET '{{typeColumn}}'= CASE WHEN '{{typeColumn}}' IS NULL THEN '{{valNum}}' ELSE '{{typeColumn}}' + '{{valNum}}' END
    WHERE denom='{{denomName}}' AND CONVERT(DATE, endtime) = CONVERT(DATE, getdate())
    END
    
ELSE
    BEGIN
    INSERT INTO dbo.c5_total_daily(denom,endtime,'{{typeColumn}}')
    VALUES ('{{denomName}}','{{endtime}}','{{valNum}}')
    END

My syntax issue is in line 11 in which I am trying to call a variable as column name. Other variable callings in this query have no issues.
Any way to avoid it?

Thanks for any tips!

Feed the template into a debug node and show us what it is generating.

[Edit] If you don't need quotes round denom and endtime, why have you put them round {{typeColumn}} ?

I tried adding quotes around denom and endtime, and also removing quotes from {{typeColumn}} but I still receive the same syntax error.
This is the debug output, I have replaced sensitive names / information with '++++'

IF EXISTS
	(SELECT 1 FROM c5_dashboard_end WHERE depositid='++++' AND endtime='2022-10-13 14:35:17')
    BEGIN
    UPDATE c5_dashboard_end
    SET ++++= CASE WHEN ++++ IS NULL THEN '260' ELSE +++++ + '260' END
    WHERE depositid='++++' AND endtime='2022-10-13 14:35:17'
    END
    
ELSE
	BEGIN
    INSERT INTO dbo.c5_dashboard_end(depositid,starttime,endtime,++++)
    VALUES ('++++','2022-10-13 14:18:17','2022-10-13 14:35:17','260')
    END
    

IF EXISTS
    (SELECT 1 FROM c5_total_daily WHERE denom='++++' AND CONVERT(DATE, endtime) = CONVERT(DATE, getdate()))
    BEGIN
    UPDATE c5_total_daily
    SET '++++'= CASE WHEN '++++' IS NULL THEN '260' ELSE '++++' + '260' END
    WHERE denom='++++' AND CONVERT(DATE, endtime) = CONVERT(DATE, getdate())
    END
    
ELSE
    BEGIN
    INSERT INTO dbo.c5_total_daily('denom','endtime','++++')
    VALUES ('++++','2022-10-13 14:35:17','260')
    END

What exactly is the error and what database is this for (mysql for example) and what node are you using to interface to it?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.