# SQL results different between n8n and SQL studio

**URL:** <https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486>\
**Category:** Questions\
**Tags:** microsoft-sql\
**Created:** [April 17, 2024, 12:47pm UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486 "2024-04-17T12:47:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://community.n8n.io/u/Jonathan)\
**Post date:** [April 17, 2024, 12:47pm UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/1 "2024-04-17T12:47:59Z")

</div>

Hi!

I’m trying to build a workflow to sync datas from a SQL database to a MySQL database. We actually are using dbsync with XMLs files, it works but we would like to change to n8n.

I’m running a first query which give me about 18000 results on SQL Management Studio. When I’m using n8n with the same query, it returns : 1 item []

What could be the reason ?

Thanks a lot for your help !

- n8n version:1.21.1
- Running n8n via (Docker, npm, n8n cloud, desktop app):npm
- Operating system:debian

---

<div class="post-metadata">

**Author:** ![n8n](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n8n/32/196425_2.png) [@n8n](https://community.n8n.io/u/n8n)\
**Post date:** [April 17, 2024, 12:48pm UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/2 "2024-04-17T12:48:00Z")

</div>

It looks like your topic is missing some important information. Could you provide the following if applicable.

- **n8n version:**
- **Database (default: SQLite):**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**
- **Operating system:**

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://community.n8n.io/u/Jonathan)\
**Post date:** [April 17, 2024, 12:49pm UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/3 "2024-04-17T12:49:56Z")

</div>

Trying to share the workflow but I get a 403 error 🫤

---

<div class="post-metadata">

**Author:** ![barn4k](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/barn4k/32/8170_2.png) [@barn4k](https://community.n8n.io/u/barn4k)\
**Post date:** [April 17, 2024, 7:17pm UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/4 "2024-04-17T19:17:15Z")

</div>

So the sql node returns 1 item with all data, or it is empty?

About 403 error: If you have html or xml node, remove it as it may be the reason.

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://community.n8n.io/u/Jonathan)\
**Post date:** [April 18, 2024, 7:38am UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/5 "2024-04-18T07:38:04Z")

</div>

In the output I have

> 1 item  
> [  
> ]

In JSON and

> 1 item  
> No data to show - item(s) exist, but they’re empty

in Schema. As far as HTML or XML in my query, I’m not sure, to me it’s pure SQL

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://community.n8n.io/u/Jonathan)\
**Post date:** [April 18, 2024, 7:44am UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/6 "2024-04-18T07:44:38Z")

</div>

Put the SQL code in a pastebin

[https://pastebin.com/8nYTmVc3](https://pastebin.com/8nYTmVc3)

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://community.n8n.io/u/Jonathan)\
**Post date:** [April 19, 2024, 7:21am UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/7 "2024-04-19T07:21:44Z")

</div>

```auto
        SELECT
          CST.[No_],
          [Name],
          CASE 
            WHEN cst.[profil] = 0 AND cst.[Client Prime] = 0 AND cst.[Gen_ Bus_ Posting Group] <> 'DOMTOM' AND cst.safety = 0 THEN 3
            WHEN cst.[profil] = 0 AND cst.[Client Prime] = 1 AND cst.[Gen_ Bus_ Posting Group] <> 'DOMTOM' AND cst.safety = 0 THEN 18
            WHEN cst.[profil] = 1 THEN 4
            WHEN cst.[profil] = 2 AND cst.safety = 0 THEN 5
            WHEN CST.[Profil] = 3 AND cst.safety = 0 AND (cst.[Criteria 1] = 'DISTRIBUTEUR' OR CST.[Profil] = 3 AND cst.[Criteria 1] = 'CHAINE') THEN 8
            WHEN CST.[Profil] = 3 AND cst.safety = 0 AND cst.[Criteria 1] = 'OPTICIEN' AND cst.[Client Prime] = 0 THEN 3
            WHEN CST.[Profil] = 3 AND cst.[Criteria 1] = 'OPTICIEN' AND cst.[Client Prime] = 1 AND cst.safety = 0 THEN 18
            WHEN CST.[Profil] = 3 AND cst.[Criteria 1] = 'AGENT' AND cst.[Client Prime] = 0 AND cst.safety = 0 THEN 3
            WHEN CST.[Profil] = 3 AND cst.[Criteria 1] = 'AGENT' AND cst.[Client Prime] = 1 AND cst.safety = 0 THEN 18
            WHEN cst.[profil] = 4 AND cst.[Client Prime] = 0 AND cst.[Gen_ Bus_ Posting Group] <> 'DOMTOM' AND cst.safety = 0 THEN 6
            WHEN cst.[profil] = 5 THEN 7
            WHEN cst.[profil] = 4 AND cst.[Client Prime] = 1 AND cst.[Gen_ Bus_ Posting Group] <> 'DOMTOM' AND cst.safety = 0 THEN 16 
            WHEN cst.[profil] = 16 AND cst.[Client Prime] = 1 AND cst.safety = 0 THEN 18
            WHEN cst.[profil] = 17 AND cst.safety = 0 THEN 17 
            WHEN cst.[profil] = 4 AND cst.[Gen_ Bus_ Posting Group] = 'DOMTOM' AND cst.safety = 0 THEN 17
            WHEN cst.[profil] = 0 AND cst.[Gen_ Bus_ Posting Group] = 'DOMTOM' AND cst.safety = 0 THEN 5
            WHEN cst.[profil] = 6 AND cst.safety = 0 THEN 9 
            WHEN cst.[profil] = 7 AND cst.safety = 0 THEN 10
            WHEN cst.[profil] = 0 AND cst.safety = 1 THEN 19
            WHEN CST.[Profil] = 8 THEN 20 
            WHEN CST.[Profil] = 9 THEN 21 
          END AS [Profil],
          CST.[Bill-to Customer No_],
          CASE WHEN CST.[Language Code] IN ('', 'FRA', 'ES') THEN 1 ELSE 6 END AS [id_lang],
          CST.[Trade Register],
          CST.[APE Code],
          RTRIM(LTRIM(CST.[E-mail])) AS [E-mail],
          '' AS [Home Page],
          CST.[Password],
          CST.[Customer Price Group],
          CST.[Criteria 6],
          CAST(COALESCE(CPG.zone, 0) AS INT) AS discount_fieldno,
          CST.[own_customer],
          CASE WHEN CST.[Currency Code] = 'USD' THEN CST.[Currency Code] ELSE '' END AS currency_code
        INTO [##Customern8n]
        FROM [dbo].[Opal$Customer] CST
        LEFT OUTER JOIN [Opal$Customer Price Group] CPG ON CST.[Customer Price Group] = CPG.Code
        WHERE [E-mail] <> '' AND [Password] <> '' AND [Published] = 1
          AND [E-Mail] LIKE '%@%'

```

Weird enough, I do have the same issue with this query on N8N, and when I paste it here I do have a 403 error as well. But, if I paste a bunch of lines, then some more, and then what’s left, I don’t have a 403 🧐

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://community.n8n.io/u/Jonathan)\
**Post date:** [April 25, 2024, 2:17pm UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/8 "2024-04-25T14:17:22Z")

</div>

Hi!

Could it be the temporary SQL table ? Does n8n handle them?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [July 24, 2024, 2:17pm UTC](https://community.n8n.io/t/sql-results-different-between-n8n-and-sql-studio/44486/9 "2024-07-24T14:17:49Z")

</div>

Closed on July 24, 2024, 2:17pm UTC

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