T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter
T-SQL DateTime Parameter T-SQL DateTime Parameter
T-SQL DateTime Parameter
Go Back  Xtreme Visual Basic Talk > > > T-SQL DateTime Parameter


Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2015, 02:25 PM
holtzy holtzy is offline
Senior Contributor
 
Join Date: Jul 2002
Location: USA
Posts: 1,054
Talking 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:
Code:
...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:
Code:
declare @varAuditDate varchar(25)
	set @varAuditDate = convert(varchar(25), @parAuditDate, 120) 
...WHERE        (fldAuditDate = '' + @varAuditDate + '')
Am I missing something simple?
__________________
God is good!!!
Reply With Quote
  #2  
Old 04-09-2015, 04:22 PM
PlausiblyDamp's Avatar
PlausiblyDampT-SQL DateTime Parameter PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,055
Default

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
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 04-10-2015, 07:28 AM
holtzy holtzy is offline
Senior Contributor
 
Join Date: Jul 2002
Location: USA
Posts: 1,054
Default

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.
__________________
God is good!!!

Last edited by holtzy; 04-10-2015 at 08:35 AM. Reason: New finding
Reply With Quote
Reply

Tags
datetime, t-sql


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter T-SQL DateTime Parameter
T-SQL DateTime Parameter
T-SQL DateTime Parameter
 
T-SQL DateTime Parameter
T-SQL DateTime Parameter
 
-->