473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Building SQL Statement

I'm currently creating an Access 2000 database to keep track of
employee vacation hours. I have a form in which the number of hours
requested off by an employee is entered into a text box. Then the
employee's remaining vacation hours are updated through a SQL update
statement. I build the SQL statement through VBA and then execute it.

Here is what my SQL looks like:
strSQL = "UPDATE Employee SET VacationTime = "
strSQL = strSQL & intNewVacation & ", "
strSQL = strSQL & "SickPersonalTime = "
strSQL = strSQL & intNewPersonal & " "
strSQL = strSQL & "WHERE EmployeeID = "
strSQL = strSQL & Me.cboEmployee.Value

Would it be more appropriate to move "me.cboEmployee.value" into a
variable, and then use the variable in the SQL statement? Or does it
even matter? I just want to be aware of any problems that might
occur. I have several SQL statements that I build this way, and I
would just like some input.

Thanks in advance for your reply,
Andrea
Nov 12 '05 #1
5 1516
DFS
"Andrea" <cl****@healingamerica.com> wrote in message
news:17*************************@posting.google.co m...
I'm currently creating an Access 2000 database to keep track of
employee vacation hours. I have a form in which the number of hours
requested off by an employee is entered into a text box. Then the
employee's remaining vacation hours are updated through a SQL update
statement. I build the SQL statement through VBA and then execute it.

Here is what my SQL looks like:
strSQL = "UPDATE Employee SET VacationTime = "
strSQL = strSQL & intNewVacation & ", "
strSQL = strSQL & "SickPersonalTime = "
strSQL = strSQL & intNewPersonal & " "
strSQL = strSQL & "WHERE EmployeeID = "
strSQL = strSQL & Me.cboEmployee.Value

Would it be more appropriate to move "me.cboEmployee.value" into a
variable, and then use the variable in the SQL statement? Or does it
even matter? I just want to be aware of any problems that might
occur. I have several SQL statements that I build this way, and I
would just like some input.
Andrea,

It doesn't really matter. Your form reference is fine (you don't need the
..Value part if you format the form control correctly). A variable would
work too, and would be better - but not required - if you moved your code to
a module outside the form:

Public Sub updateEmployeeData(employeeID as integer, vacationHrs as integer,
sickTime as integer)
strSQL = "UPDATE Employee
strSQL = strSQL & "SET VacationTime = " & vacationHrs & ", "
strSQL = strSQL & "SickPersonalTime = " & sickTime & " "
strSQL = strSQL & "WHERE EmployeeID = " & employeeID & ";"
End Sub

Thanks in advance for your reply,
Andrea

Nov 12 '05 #2
Using a direct reference to a value is usually prefered over stored ones.
There's nothing wrong with how you've used it here.
(Provided the syntax is correct)

Mike Storr
www.veraccess.com

"Andrea" <cl****@healingamerica.com> wrote in message
news:17*************************@posting.google.co m...
I'm currently creating an Access 2000 database to keep track of
employee vacation hours. I have a form in which the number of hours
requested off by an employee is entered into a text box. Then the
employee's remaining vacation hours are updated through a SQL update
statement. I build the SQL statement through VBA and then execute it.

Here is what my SQL looks like:
strSQL = "UPDATE Employee SET VacationTime = "
strSQL = strSQL & intNewVacation & ", "
strSQL = strSQL & "SickPersonalTime = "
strSQL = strSQL & intNewPersonal & " "
strSQL = strSQL & "WHERE EmployeeID = "
strSQL = strSQL & Me.cboEmployee.Value

Would it be more appropriate to move "me.cboEmployee.value" into a
variable, and then use the variable in the SQL statement? Or does it
even matter? I just want to be aware of any problems that might
occur. I have several SQL statements that I build this way, and I
would just like some input.

Thanks in advance for your reply,
Andrea

Nov 12 '05 #3
Thank you for your replies, I just needed to know that I was on the
right track. I appreciate your input.

Thanks again!
Andrea
Nov 12 '05 #4
Hi Andrea,

Just a suggestion -

Using line continuation characters makes your code more readable and
it's quicker to type too.

strSQL = "SELECT field1, field2 " & _
"FROM tbl1 " & _
"WHERE field2 = 'x' " & _
"ORDER BY field1"

I currently work on a database with lots of code using the method you
posted (the guy never moved beyond Access 2 code)

eg. strSQL = strSQL & "FROM tbl1 "
strSQL = strSQL & "WHERE etc "

and it ain't pretty.

Hope you don't mind my suggestion and it helps your code readability.

Regards,

Peter

cl****@healingamerica.com (Andrea) wrote in message news:<17**************************@posting.google. com>...
Thank you for your replies, I just needed to know that I was on the
right track. I appreciate your input.

Thanks again!
Andrea

Nov 12 '05 #5
Hi Mike,
Using a direct reference to a value is usually prefered over stored ones.
Depends how many times you use it, doesn't it?

In a loop it would be quick to use a variable than reference a control n times.

Of course in this case it's an extra line of unneeded code.

Regards,

Peter

"Mike Storr" <st******@sympatico.ca> wrote in message news:<7V**********************@news20.bellglobal.c om>... Using a direct reference to a value is usually prefered over stored ones.
There's nothing wrong with how you've used it here.
(Provided the syntax is correct)

Mike Storr
www.veraccess.com

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Greg Lindstrom | last post by:
Hello- I am working on a routine to pull information from an Oracle database and format it into fixed-length records. My problem is that the record layout is quite long (over 500 bytes) and...
9
by: Jenta | last post by:
A World Beyond Capitalism 2005, An Annual International Multiracial Alliance Building Peace Conference Is Accepting Proposals... ...and Online Registration is now available if you plan to table...
2
by: beyond | last post by:
i need a sql-statement for this problem i ve got a table like this ID;value 1;30 2;34 3;44 the result of sql-statement should calculate differences to previous/other datasets like this
2
by: Jack | last post by:
Hi, I am trying to update database from asp. However, the finalupdate field is not working here. The finalupdate field is a Access Database field of type yes/no. Any help/advise is appreciated....
4
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
2
by: Mossy | last post by:
I am currently moving a table from a msSQL DB to a MySQL DB. I am trying to build the bones of an insert statement by adding strings to a select statement. SELECT '(' + job_referenceno + ',...
3
by: visionstate | last post by:
Hi All, I have used the following article to help me build a query 'on the fly': http://www.fontstuff.com/access/acctut17.htm It's a very useful article and is exactly what I was looking for to...
6
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. ...
17
by: john | last post by:
All: I'm a long-time developer, new to PHP.... Is there an idiom used in PHP to construct SQL statments from $_POST data? I would guess that in many applications, the data read from $_POST...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.