georgepatotk Posted September 13, 2004 Posted September 13, 2004 can anyone tell me what's wrong with the querystring below? sqlquery = "SELECT * FROM tblBuys WHERE convert(varchar, BuyDate,103) = '" & Format(Date.Today, "dd/mm/yyyy") & "' ORDER BY BuyKey" Thanks in advance. Quote George C.K. Low
Mykre Posted September 13, 2004 Posted September 13, 2004 What error are you getting... Also Have you tried adding the size of the varchar to be created. sqlquery = "SELECT * FROM tblBuys WHERE convert(varchar(20), BuyDate,103) = '" & Format(Date.Today, "dd/mm/yyyy") & "' ORDER BY BuyKey" can anyone tell me what's wrong with the querystring below? sqlquery = "SELECT * FROM tblBuys WHERE convert(varchar, BuyDate,103) = '" & Format(Date.Today, "dd/mm/yyyy") & "' ORDER BY BuyKey" Thanks in advance. Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Administrators PlausiblyDamp Posted September 13, 2004 Administrators Posted September 13, 2004 You may be better of parameterising the query or using a stored proc rather than converting the dates to strings and then doing string comparisons on them. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georgepatotk Posted September 13, 2004 Author Posted September 13, 2004 I got the solution: sqlquery = "SELECT * FROM tblBuys WHERE BuyDate= #" & Date.Today & "# ORDER BY BuyKey" Quote George C.K. Low
*Experts* Nerseus Posted September 13, 2004 *Experts* Posted September 13, 2004 Also, make sure you mention the Database you're using as the formatting of dates is different for Access vs. SQL Server (for example). I'm glad you removed the "CONVERT" from your date column. If it were already a date, there was no need to convert it. Plus, a convert to varchar would not only be slower (the DB would have to convert every row) but the compare would be slower (string based vs. date based). The only thing I'd suggest adding is the use of ToString on the date: sqlquery = "SELECT * FROM tblBuys WHERE BuyDate= #" & Date.Today.ToString("MM/dd/yyyy") & "# ORDER BY BuyKey" -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.