# MSSQL plus declaration error

**URL:** <https://discourse.nodered.org/t/mssql-plus-declaration-error/96249>\
**Category:** General\
**Created:** [25 March 2025 14:01 UTC](https://discourse.nodered.org/t/mssql-plus-declaration-error/96249 "2025-03-25T14:01:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArcelorMan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arcelorman/32/99548_2.png) [@ArcelorMan](https://discourse.nodered.org/u/ArcelorMan)\
**Post date:** [25 March 2025 14:01 UTC](https://discourse.nodered.org/t/mssql-plus-declaration-error/96249/1 "2025-03-25T14:01:51Z")

</div>

When i attempt to query with userinput, i get an error claiming my var is undeclared, yet following the node page, this is how it should be declared, right?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/5/4579ec74c2b8703b39c5b78d78b7ec7c0066e9ed.png)

```auto
msg.topic = `
   SELECT DISTINCT [EmployeeID (SIDxxxx)] 
   FROM NR_EmployeeInformation
   WHERE Email = @userInput
      OR EmployeeID = @userInput
      OR Tel = @userInput
      OR Voornaam = @userInput
      OR Achternaam = @userInput
      OR CONCAT(Voornaam, Achternaam) = @userInput
      OR CONCAT(Achternaam, Voornaam) = @userInput
      OR Email LIKE '%' + @userInput + '%'
      OR Tel LIKE '%' + @userInput + '%'
      OR Voornaam LIKE '%' + @userInput + '%'
      OR Achternaam LIKE '%' + @userInput + '%';
      OR EmployeeID LIKE '%' + @userInput + '%'
`;

msg.params = { name: 'userInput', Value: msg.payload };
return msg;

```

```auto
3/25/2025, 2:58:06 PMnode: debug 6
SELECT DISTINCT [EmployeeID (SIDxxxx)] FROM NR_EmployeeInformation WHERE Email = @userInput OR EmployeeID = @userInput OR Tel = @userInput OR Voornaam = @userInput OR Achternaam = @userInput OR CONCAT(Voornaam, Achternaam) = @userInput OR CONCAT(Achternaam, Voornaam) = @userInput OR Email LIKE '%' + @userInput + '%' OR Tel LIKE '%' + @userInput + '%' OR Voornaam LIKE '%' + @userInput + '%' OR Achternaam LIKE '%' + @userInput + '%'; OR EmployeeID LIKE '%' + @userInput + '%' : msg : Object
object
_client: object
payload: "SIDp"
topic: "↵ SELECT DISTINCT [EmployeeID (SIDxxxx)] ↵ FROM NR_EmployeeInformation↵ WHERE Email = @userInput↵ OR EmployeeID = @userInput↵ OR Tel = @userInput↵ OR Voornaam = @userInput↵ OR Achternaam = @userInput↵ OR CONCAT(Voornaam, Achternaam) = @userInput↵ OR CONCAT(Achternaam, Voornaam) = @userInput↵ OR Email LIKE '%' + @userInput + '%'↵ OR Tel LIKE '%' + @userInput + '%'↵ OR Voornaam LIKE '%' + @userInput + '%'↵ OR Achternaam LIKE '%' + @userInput + '%';↵ OR EmployeeID LIKE '%' + @userInput + '%'↵"
_msgid: "35b372c405abf8d8"
params: object
query: "↵ SELECT DISTINCT [EmployeeID (SIDxxxx)] ↵ FROM NR_EmployeeInformation↵ WHERE Email = @userInput↵ OR EmployeeID = @userInput↵ OR Tel = @userInput↵ OR Voornaam = @userInput↵ OR Achternaam = @userInput↵ OR CONCAT(Voornaam, Achternaam) = @userInput↵ OR CONCAT(Achternaam, Voornaam) = @userInput↵ OR Email LIKE '%' + @userInput + '%'↵ OR Tel LIKE '%' + @userInput + '%'↵ OR Voornaam LIKE '%' + @userInput + '%'↵ OR Achternaam LIKE '%' + @userInput + '%';↵ OR EmployeeID LIKE '%' + @userInput + '%'↵"
queryMode: "query"
queryParams: array[0]
error: object
class: 15
code: "EREQUEST"
lineNumber: 4
message: "Must declare the scalar variable "@userInput"."
details: "Must declare the scalar variable "@userInput"."
name: "RequestError"
number: 137
procName: ""
serverName: "SQL16PROD2\V02"
state: 2
toString: function

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 March 2025 15:13 UTC](https://discourse.nodered.org/t/mssql-plus-declaration-error/96249/2 "2025-03-25T15:13:56Z")

</div>

> [@ArcelorMan](#):
>
> `LIKE '%' + @userInput + '%'`

This is not valid usage.

  

> [@ArcelorMan](#):
>
> `OR Achternaam LIKE '%' + @userInput + '%';`

This line has a semicolon

  

> [@ArcelorMan](#):
>
> `msg.params = { name: 'userInput', Value: msg.payload };`

- `Value` is not the same as `value`
- `type` is missing
- should be an array as per the built in help:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/836f098c8ca21365a3ceda2f39a5c27837b3d185.png)

  
  

Try using the editor instead

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57060a07386e36190af4a87dc1d75b7d813c9a8f.png)

---

<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:** [8 April 2025 15:14 UTC](https://discourse.nodered.org/t/mssql-plus-declaration-error/96249/3 "2025-04-08T15:14:10Z")

</div>

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