Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Database and Reporting (http://www.xtremevbtalk.com/-net-database-and-reporting/)
-   -   T-SQL DateTime Parameter (http://www.xtremevbtalk.com/-net-database-and-reporting/327562-sql-datetime-parameter.html)

holtzy 04-09-2015 01:25 PM

T-SQL DateTime Parameter
There are posts all over the web about DateTime Parameters in stored procedures, but I still cannot figure this out. I have a parameter that gets passed in successfully as a datetime (@parAuditDate datetime), but when I use it in a query:

...WHERE        (fldAuditDate = @parAuditDate)
it always returns zero rows. However, if I convert it to a varchar before I use it in the query, it returns a row:

declare @varAuditDate varchar(25)
        set @varAuditDate = convert(varchar(25), @parAuditDate, 120)
...WHERE        (fldAuditDate = '' + @varAuditDate + '')

Am I missing something simple?

PlausiblyDamp 04-09-2015 03:22 PM

What is the data type of the underlying column? If it is a datetime then you shouldn't need to wrap the parameter in single quotes.

Just ... WHERE fldAuditDate = @varAuditDate

holtzy 04-10-2015 06:28 AM

The column is a datetime data type. Doesn't make sense to me.

EDIT: What is really weird is that the datetime works if it is an Update query, but for some reason it won't match on a select query.

All times are GMT -6. The time now is 06:00 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.