How to code this SQL ?

  • Thread starter Thread starter TA
  • Start date Start date
T

TA

Dear all,
Could you help me to correct for this SQL code. I enter in
the form but it is error. Access2K
I want to select month=1 or 2 or 3 and year 2001.

Set RsQ12001 = DB.OpenRecordset _
("SELECT * FROM dbo_cum where (testmon="01" or
testmon="02", or tetsmon="03") and testyr"2001" ",
dbOpenDynaset, dbSeeChanges)

Best Regards,
TA
 
If I understand, you have a table named dbo_cum, with a
field named textmon that has data stored as text, with two
chars (01,02,etc). There is another field named textyr
that is text, with the year as four chars.

Try using single quotes for the text to compare and spaces
before and after the equal signs.

This is air code - the select statement should be one line
I think the semi-colon is needed; try it without if there
is an error.

Set RsQ12001 = DB.OpenRecordset _
("SELECT * FROM dbo_cum WHERE (testmon = '01' or
testmon = '02' or testmon = '03') and testyr = '2001' ;",
dbOpenDynaset, dbSeeChanges)


HTH

Steve S
 
Have you tried....

Dim strSQL as String

strSQL = "SELECT dbo_cum.* " _
& "FROM dbo_cum " _
& "WHERE dbo_cum.testmon IN ('1', '2','3')" _
& " AND dbo_cum.testyr = '2001';"
 
Back
Top