I'm working on an ASP Web application, and am having syntax issues in
a WHERE statement I'm trying to write that uses the CInt Function on a
field.
Basically, I want to select records using criteria of Race, Gender and
Crime Code. But the Crime Code field in the table is text, and I
cannot change it. I want to use a range of crime codes, so need to
convert it to an integer on-the-fly. Here's what I have in my code so
far:
varSQL = "SELECT PrisonRelease.* , Defendant.*, Arrest.* "
varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
ARREST on DEFENDANT.Defen dant_ID = ARREST.Defendan t_ID) ON
PrisonRelease.P ID = Defendant.PID_C ode "
varSQL = varSQL & "WHERE DEFENDANT.Race_ Type_Code_L in (" &
varRaceList & ")AND DEFENDANT.Gende r In (" & varGenderList & ") "
varSQL = varSQL & "AND
(IIf(IsNull(Def endant.[CRIME_CLASSIFIC ATION_CODE]) Or
Defendant.[CRIME_CLASSIFIC ATION_CODE]="" Or
(Defendant.[CRIME_CLASSIFIC ATION_CODE]) Not Like "[0-9][0-9][0-9]" And
Defendant.[CRIME_CLASSIFIC ATION_CODE] Not Like
"[0-9][0-9][0-9][0-9]"),9999,CInt(De fendant.[CRIME_CLASSIFIC ATION_CODE])
Between 1800 And 1899) "
When I try to execute this code on my Web page, I get an error. But it
works fine in Access, with some minor syntax changes. What am I
missing?!
Thanks,
Rachel Weeden
a WHERE statement I'm trying to write that uses the CInt Function on a
field.
Basically, I want to select records using criteria of Race, Gender and
Crime Code. But the Crime Code field in the table is text, and I
cannot change it. I want to use a range of crime codes, so need to
convert it to an integer on-the-fly. Here's what I have in my code so
far:
varSQL = "SELECT PrisonRelease.* , Defendant.*, Arrest.* "
varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
ARREST on DEFENDANT.Defen dant_ID = ARREST.Defendan t_ID) ON
PrisonRelease.P ID = Defendant.PID_C ode "
varSQL = varSQL & "WHERE DEFENDANT.Race_ Type_Code_L in (" &
varRaceList & ")AND DEFENDANT.Gende r In (" & varGenderList & ") "
varSQL = varSQL & "AND
(IIf(IsNull(Def endant.[CRIME_CLASSIFIC ATION_CODE]) Or
Defendant.[CRIME_CLASSIFIC ATION_CODE]="" Or
(Defendant.[CRIME_CLASSIFIC ATION_CODE]) Not Like "[0-9][0-9][0-9]" And
Defendant.[CRIME_CLASSIFIC ATION_CODE] Not Like
"[0-9][0-9][0-9][0-9]"),9999,CInt(De fendant.[CRIME_CLASSIFIC ATION_CODE])
Between 1800 And 1899) "
When I try to execute this code on my Web page, I get an error. But it
works fine in Access, with some minor syntax changes. What am I
missing?!
Thanks,
Rachel Weeden
Comment