# MSSQL in a function

**URL:** <https://discourse.nodered.org/t/mssql-in-a-function/73878>\
**Category:** General\
**Tags:** database, function-node\
**Created:** [18 January 2023 18:19 UTC](https://discourse.nodered.org/t/mssql-in-a-function/73878 "2023-01-18T18:19:11Z")\
**Posts on this page:** 1\
**Showing post:** 14

<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:** [18 January 2023 23:10 UTC](https://discourse.nodered.org/t/mssql-in-a-function/73878/14 "2023-01-18T23:10:09Z")

</div>

> [@pkdata-pkthedj](#):
>
> im using ms-sql plus

Firstly, you are setting msg.topic but have the SQL node set to use the internal SQL editor.

Secondly, you should use parameters for this. Especially for dates & times as getting the correct format date string is often difficult.

The better way to do a request is enter the SQL in the mssql node & use parameters

Example..

```auto
SELECT * FROM [Dev].[dbo].[MQTTData] 
WHERE 
Timestamp BETWEEN (@startDate AND @endDate)

```

where @startDate & @endDate are entered in the "parameters" section & mapped to the correct property in the msg and set for the intended type.

Here is a previous working example

> [@SQL data return array data types? MSSQL Node](https://discourse.nodered.org/t/sql-data-return-array-data-types-mssql-node/72157/3):
>
> Also, when using SQL Server (or any SQL), you should avoid building string queries as it opens you up to [SQLi hacks](https://en.wikipedia.org/wiki/SQL_injection) Here is how you would (should) do this using node-red-contrib-MSSQL-PLUS [image]

---

_[View the full topic](https://discourse.nodered.org/t/mssql-in-a-function/73878)._
