SQL Query runs in Visual Studio SQL Tools but fails during runtime

SSMS returns correct results for my SQL script, yet executing it in C# gives an empty data grid. A new test code:

DECLARE @testDate DATE = '2021-01-01';
SELECT vehicleID FROM AutoRecords 
WHERE vehicleID NOT IN (SELECT vehicleID FROM ActivityLog WHERE logDate = @testDate);

Why does this discrepancy occur?

hey, im thinkin its a binding issue. ssms and c# might handle the @testdate diffirently. u gotta verify how you’re passing the param. i had similar probs and fixing that did the trick for me, cheers.

I have seen similar discrepancies where the SQL runs correctly in SSMS but behaves differently during runtime in C#. One potential cause may be the way parameters are added to the command in the C# application. In my experience, ensuring that the datatype of the parameter in C# exactly matches the datatype expected by the SQL script is crucial. It may be worthwhile to log the actual query sent to the database or use SQL Profiler to identify any device-specific transformations or omissions upon execution in your application.