473,320 Members | 1,976 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,320 software developers and data experts.

Syntax Error in Simple SQL Statement?

Hi there!

I'm trying to group employees into age groups to see percentages per age group. This is my code:

Expand|Select|Wrap|Line Numbers
  1. SELECT [CSH Employees].DOB, [CSH Employees].status
  2. FROM [CSH Employees]
  3. WHERE (([CSH Employees].status)<>"former")
  4.  
  5. Public Function AgeGroup(DOB As Date) As String
  6.  
  7.     Dim intAge As Integer
  8.  
  9.     'Age Calculation
  10.     intAge = DateDiff("yyyy", [DOB], Now()) + _
  11.              Int(Format(Now(), "mmdd") < Format([DOB], "mmdd"))
  12.  
  13.     Select Case intAge
  14.  
  15.         'For each Age range, write out Age Group (used in qry)
  16.     CaseIs < 30
  17.         AgeGroup = "<30"
  18.     Case 30 to 44
  19.         AgeGroup = "30-44"
  20.     Case 45 to 59
  21.         AgeGroup = "45-59"
  22.     Case Is > 59
  23.         AgeGroup = "60+"
  24.      End Select
  25.  
  26. End Function
I'm getting this error:

Syntax error (missing operator) in query expression '(([CSH Employees].status)<>"former")
Public Function AgeGroup(DOB As Date) As String
Dim intAge As Integer
'Age Calculation
intAge = DateDiff("yyyy", [DOB], Now()) + _
Int(Format(Now(), "mmdd") < Format([DOB], "mmdd"))

What am I missing or doing wrong?
Jun 21 '12 #1
1 1569
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

Did you try to use VBA code in SQL? You can't do that. the VBA code needs to go in a module and then you call it from a SQL query. Also, no where in your SQL do you call the function you define.
Jun 21 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
2
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
1
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line...
2
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am basically adding a datarow and then passing the...
1
by: jomurf | last post by:
Not sure if this is the right forum. I'm using Microsoft Query to get data from our ERP. However, every time I try to sum a column, I get a syntax error. Here's the sql statement: SELECT...
7
by: Dustin MacDonald | last post by:
Hi everyone. This is my first time posting to this newsgroup, and although I maintain my netiquette I might've missed something specific to the newsgroup, so hopefully you can avoid flaming me...
1
by: Michel Esber | last post by:
Hello, DB2 LUW v8 FP15 I am running a simple 'runstats on table session.temp_MID_1 and indexes all' and it fails with SQLAllocStmt( phStmt=4:2 ) <--- SQL_SUCCESS Time elapsed -
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.