SQL server node result return

Hi community

I haver a question, It’s possible change sql server node result return ?

Accually when we make a query that returns no result the node returns “empty values” this is bad when we have colunns reference anote node, because reference is missing resulting unespected behaviour. It’s possible changes results with row and colums with empty values exactly sql server does?

Did you try activating “Always Output Data” under the node settings? That should make sure that at least an empty JSON gets returned if there is no data.

Yes,

This is my flow

I send a messenger from my personal number, if this number is in sql database, ill receive one messenger template, if the number isn’t in my database, i’ll get another template.

When in IF is true, everything works good, see IF

Value 1 = Comes from webhook

Value 2 = Comes from my database (especified column)

Now, if I send messenger from my wife number for example,

Maybe always output data doesn’t work correctly. At least to me, doesn’t work or output in sql should be like a demonstrated last on last pic

Hi @Fabio_Valentim, this is the correct and intended behavior I am afraid:

An empty item doesn’t technically have any keys (which could be rendered as column A, column B, column C) so that’s why n8n won’t show any columns here.

Perhaps you could share your workflow (simply select it on the canvas and paste it here on the forum)? That way we might be able to find a suitable workaround for these missing columns in your Set or HTTP Request nodes :slight_smile:

That is the point, returns should bring columns names from schema even there is no value return from query.

I’ll put here ASAP

I supposed SQL Server Node should have SQL Server behaviour, “This output item is empty” isn’t default return from SQL, for example, below we have return from simple query

SELECT nome, celular, filial FROM USERS WHERE celular like ‘5581999999999’

This number doesn’t exist on my database, then, my sql return is
image

On IF NODE I’m considering if result brings or not a value, based on column, this is a normal behavour from SQL, This output item is empty is a implemented output but with all respect, it’s not right,

{
“nodes”: [
{
“parameters”: {},
“name”: “Start”,
“type”: “n8n-nodes-base.start”,
“typeVersion”: 1,
“position”: [
200,
0
]
},
{
“parameters”: {
“httpMethod”: “POST”,
“path”: “1f8af868-0000-0000-0000-c793ff0000d5”,
“options”: {}
},
“name”: “Webhook”,
“type”: “n8n-nodes-base.webhook”,
“typeVersion”: 1,
“position”: [
460,
0
],
“webhookId”: “1f8af868-0000-0000-000-c793ff00005”
},
{
“parameters”: {
“conditions”: {
“number”: [
{
“value1”: “={{$node[“Webhook”].json[“body”][“entry”][0][“changes”][0][“value”][“contacts”][0][“wa_id”]}}”,
“operation”: “equal”,
“value2”: “={{$node[“Microsoft SQL”].json[“celular”]}}”
}
]
}
},
“name”: “IF1”,
“type”: “n8n-nodes-base.if”,
“typeVersion”: 1,
“position”: [
940,
0
],
“alwaysOutputData”: true,
“continueOnFail”: true
},
{
“parameters”: {
“operation”: “executeQuery”,
“query”: “=select NOME , celular , filial from USUARIOS where filial = 1 and celular = ‘{{$json[“body”][“entry”][0][“changes”][0][“value”][“contacts”][0][“wa_id”]}}’”
},
“name”: “Microsoft SQL”,
“type”: “n8n-nodes-base.microsoftSql”,
“typeVersion”: 1,
“position”: [
700,
0
],
“alwaysOutputData”: true,
“notesInFlow”: false,
“credentials”: {
“microsoftSql”: {
“id”: “1”,
“name”: “Microsoft SQL account”
}
},
“continueOnFail”: true
}
],
“connections”: {
“Webhook”: {
“main”: [
[
{
“node”: “Microsoft SQL”,
“type”: “main”,
“index”: 0
}
]
]
},
“Microsoft SQL”: {
“main”: [
[
{
“node”: “IF1”,
“type”: “main”,
“index”: 0
}
]
]
}
}
}

@MutedJam :grimacing:

Hi @Fabio_Valentim, I can see where you are coming from, but that’s not how n8n works at the moment I am afraid. You could use a Set node though to add missing fields if needed:

In this example I am using an expression of {{$json["myOtherField"] || ""}}. This expression keeps the existing value of myOtherField if present, but if not it would set an empty string (""). In the screenshot above you can see how my second item doesn’t have myOtherField when arriving at the Set node, but does have it afterwards.

Here’s my example workflow:

Understood @MutedJam, thanks a lot for your reply.

Later, at home, I’ll make these changes no my workflow and post here result ASAP

Hi Jam, its worked for me, is a very nice trick using " || " logic operator. I realized too my IF NODE had enabled execute on fail enabled this make sometimes both true and false conditions returnes.

1 Like

Awesome, glad to hear this works for you!