MSSQL in a function

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..

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