# Syntax issues with SQL

**URL:** https://discourse.nodered.org/t/syntax-issues-with-sql/68978
**Category:** General
**Created:** [13 October 2022 10:46 UTC](https://discourse.nodered.org/t/syntax-issues-with-sql/68978 "2022-10-13T10:46:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![milner236](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@milner236](https://discourse.nodered.org/u/milner236)
#### Post date: [13 October 2022 10:46 UTC](https://discourse.nodered.org/t/syntax-issues-with-sql/68978/1 "2022-10-13T10:46:57Z")

</div>

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)

```auto
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!

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [13 October 2022 11:12 UTC](https://discourse.nodered.org/t/syntax-issues-with-sql/68978/2 "2022-10-13T11:12:47Z")

</div>

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}} ?

---

<div class="post-metadata">

### Author: ![milner236](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@milner236](https://discourse.nodered.org/u/milner236)
#### Post date: [13 October 2022 11:43 UTC](https://discourse.nodered.org/t/syntax-issues-with-sql/68978/3 "2022-10-13T11:43:08Z")

</div>

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 '++++'

```auto
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

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [13 October 2022 12:31 UTC](https://discourse.nodered.org/t/syntax-issues-with-sql/68978/4 "2022-10-13T12:31:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [12 December 2022 12:31 UTC](https://discourse.nodered.org/t/syntax-issues-with-sql/68978/5 "2022-12-12T12:31:38Z")

</div>

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