Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > SQL Query doesnt return right value


Reply
 
Thread Tools Display Modes
  #1  
Old 03-02-2011, 08:16 PM
cuber_killua's Avatar
cuber_killua cuber_killua is offline
Contributor
 
Join Date: Sep 2004
Location: Philippines
Posts: 405
Default SQL Query doesnt return right value


hi guys!!! can you please help with this query, it seems that this query doesnt read the begindate and only displays record with enddate.

Code:
str = ""
str = str & "Select sum(quantity) as totalpurchase from purchaseorder where itemcode='" & itmcode & "' and"
str = str & " category='Consumables' and company='" & company & "' and (datereceive >= '" & datebegin & "' and datereceive <= '" & dateend & "')"
str = str & "  and (postatus='received' or postatus='oh-hand')"
i am using vb2010 and mysql community server.
Reply With Quote
  #2  
Old 03-02-2011, 11:09 PM
Qua's Avatar
Qua Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Location: 127.0.0.1
Posts: 2,171
Default

Could you be more specific with the error. Does the query ignore the datareceive condition but comply with the dateend condition?

Have you verified that both dates are in a correct format before you insert them in the query?
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 03-06-2011, 03:33 PM
Chris Allen's Avatar
Chris Allen Chris Allen is offline
Centurion
 
Join Date: Jul 2005
Posts: 167
Default

Quote:
Originally Posted by cuber_killua View Post
hi guys!!! can you please help with this query, it seems that this query doesnt read the begindate and only displays record with enddate.

Code:
str = ""
str = str & "Select sum(quantity) as totalpurchase from purchaseorder where itemcode='" & itmcode & "' and"
str = str & " category='Consumables' and company='" & company & "' and (datereceive >= '" & datebegin & "' and datereceive <= '" & dateend & "')"
str = str & "  and (postatus='received' or postatus='oh-hand')"
i am using vb2010 and mysql community server.
Try below, if you are using dates you need to use the # sign around them.


str = ""
str = str & "Select sum(quantity) as totalpurchase from purchaseorder where itemcode='" & itmcode & "' and"
str = str & " category='Consumables' and company='" & company & "' and (datereceive >= #" & datebegin & "# and datereceive <= #" & dateend & "#)"
str = str & " and (postatus='received' or postatus='oh-hand')"
__________________
If All Else Fails... Ask
Reply With Quote
  #4  
Old 03-07-2011, 06:14 PM
cuber_killua's Avatar
cuber_killua cuber_killua is offline
Contributor
 
Join Date: Sep 2004
Location: Philippines
Posts: 405
Default

Thanks for the help.. its ok now guys.. Qua is right i forgot to format the date to match the date format of MySQL, i didnt notice that part... it should be;
Code:
format(datebegin, "yyyy-MM-dd")
same as well as dateend.. and another thing, MySQL doesnt use hash sign for date query..
thanks again..
Reply With Quote
Reply


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