Question Locked

sql queries and visual basic

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i want to query two related access tables in vb 6 and dispaly the records in a datagrid but i am getting an error message.see example code below
sql1 = ("select * from Statistics,Hospital Where ")

sql1 = ("sql1 & statistics.Hospital = 'hospital.hospital' & hospital.class='Referal ' & or & hospital.class ='provincial' ")
'sql1 = (" sql1 & & and disease = 'cancer' ")

2 replies

by tony hopkinson

sql1 = "select * from Statistics,Hospital Where "

sql1 = sql1 & "statistics.Hospital = hospital.hospital and hospital.class='Referal '"
sql1 = sq11 & " or hospital.class ='provincial' "
sql1 = sql1 & " and disease = 'cancer' ")

& = concatenate string
and = logicaland in sql
" delimits strings in VB and objects in SQL like [] does
' delimits strings in SQL

Debug would have showed you sql1 =

" sql1 & & and disease = 'cancer'"

Yoy might want to stick some parentheses in the SQL as well just to make it clear.

Guessing I'd say you wanted records
where statistics.hospital = hospital.hospital and (hospital.class = 'referal' or hospital.class = 'provincial') and disease = 'cancer'

but it is a guess, the paretheses will remove the ambiguity.

This discussion is closed to new replies.