Share via

How to bind the SQL query datetime string literal with datetime instead of datetime2 with SNAC 11 driver in case of SQLBindParameter().

Anonymous
2023-11-08T06:51:17+00:00

While using the SNAC 11 driver for ODBC connection with our application, the query that is filtering on a datetime field and comparing it to a datetime value on the right of the comparison generates the SQL query with a program variable bound to the datetime2 datatype instead of datetime, which is not the case with the SQL Server driver. The following are the SQL statements observed using the SQL Server profiler for SNAC11 and the SQL Server driver, respectively:

declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 int,@P2 datetime2',N'SELECT "prrowid", "custnum", "country", "name", "address", "address2", "city", "state", "postalcode", "contact", "phone", "salesrep", "creditlimit", "balance", "terms", "discount", "comments", "fax", "emailaddress", "Pro2SrcPDB", "pro2created", "pro2modified" FROM "sports2000"."dbo"."customer" WHERE (("custnum" > @P1) AND ("pro2created" <= @P2)) ORDER BY "prrowid" ',5,'2023-08-10 14:39:55.5770000'
select @p1

declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@P1 int,@P2 datetime',N'SELECT "prrowid", "custnum", "country", "name", "address", "address2", "city", "state", "postalcode", "contact", "phone", "salesrep", "creditlimit", "balance", "terms", "discount", "comments", "fax", "emailaddress", "Pro2SrcPDB", "pro2created", "pro2modified" FROM "sports2000"."dbo"."customer" WHERE (("custnum" > @P1) AND ("pro2created" <= @P2)) ORDER BY "prrowid" ',5,'2023-08-10 15:03:34.400'
select @p1

Windows for home | Windows 10 | Devices and drivers

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. JuliaMarvin 19,910 Reputation points Volunteer Moderator
    2023-11-08T06:54:18+00:00

    Suggest re-asking here: SQL Server - Microsoft Q&A

    Was this answer helpful?

    0 comments No comments