|
-
Mar 28th, 2018, 08:09 AM
#1
Thread Starter
Fanatic Member
Using Parameters in Queries
I wrote an app about ten years ago using VB 6.0. It connects to an Oracle back-end and it's been humming along pretty well for that time with periodic updates to functionality. I primarily work as a Data Analyst so I don't code every day and while I've written some VB.NET apps, you could say my skills aren't exactly polished any more. Were they ever? 
Anyway, the program does a lot of data retrieval/manipulation using queries. Select, Insert, Update, Delete -- all of it. I had a problem for the longest time where the regional settings on the user's computer had to be set a certain way or the app wouldn't work. I rewrote the SQL to include To_Date functions on the dates in question and that seemed to fix it.
I'm now tasked with converting the SQL to work with SQL Server as our company is trying to get off Oracle. A few searches of this forum led me to something I had never seen before; using parameters in the SQL. Wow, makes sense!
I got a few queries working with parameters and I can see the advantages for sure. But I have a couple of questions...
1) When I say "Where TABLE.DATE >= ? and TABLE.DATE <=?" in my query, it returns dates from well outside the range I ask for. Using Between instead seems to fix the issue. That leads me to question 2...
2) Is there anything I need to do in the SQL itself to work with the date? I identify it's a date in my parameter (below), but I wonder how it knows what format my date is in. Do I need to add a CAST statement (or something like that) to the SQL statement so it knows what format my date is in?
Code:
.Parameters.Append .CreateParameter("StartDate", adDate, adParamInput, , dtStartDate)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|