I have a simple query which selects a few lines, has two inner joins and has a couple of where statements.
However the line WHERE g.company BETWEEN '2' AND '21' isn't working as i expect.
Current Code
SELECT
g.date_reg AS Date_Entered,
g.userid AS UserID,
x.account AS Account_Number,
g.company AS Company_Number
FROM gtable g
INNER JOIN MSI f ON g.vt= f.vt AND g.company = f.company AND g.vn = f.vn
INNER JOIN grow x ON f.vn = x.vn AND f.cb = x.cb AND (f.dac = x.ca OR f.dad = x.da)
WHERE g.company BETWEEN '2' AND '21'
AND g.vn = '123123456'
AND g.year = '2014'
With the current code i get the following result.
Date_Entered UserID Account_Number Company_Number
01/01/2014 AB01 1112 20
if i change that line to WHERE g.company BETWEEN '1' AND '21' I get the following:
Date_Entered UserID Account_Number Company_Number
03/03/2014 CD01 1312 19
02/02/2014 BG01 1412 19
01/01/2014 AB01 1112 20
Which doesn't make sense as I have only changed the lower bounds.
Then even more strange, if i change it to WHERE g.company BETWEEN '0' AND '21'
I get the following:
Date_Entered UserID Account_Number Company_Number
03/03/2014 CD01 1312 02
02/02/2014 BG01 1412 02
03/03/2014 CD01 1312 03
02/02/2014 BG01 1412 05
03/03/2014 CD01 1312 05
02/02/2014 BG01 1412 05
03/03/2014 CD01 1312 06
02/02/2014 BG01 1412 06
03/03/2014 CD01 1312 07
02/02/2014 BG01 1412 07
03/03/2014 CD01 1312 07
02/02/2014 BG01 1412 07
03/03/2014 CD01 1312 07
02/02/2014 BG01 1412 08
03/03/2014 CD01 1312 08
02/02/2014 BG01 1412 08
03/03/2014 CD01 1312 09
02/02/2014 BG01 1412 09
03/03/2014 CD01 1312 19
02/02/2014 BG01 1412 19
01/01/2014 AB01 1112 20
What I want from the where statement is to show any company that has a number between and including 2 and 21 inclusive.
'2' <> '02'same thing applies for other valuesWHERE g.company IN ('01', '02', '03', '04').