Aditii
Aditii

Reputation: 355

Using variable with query

I have a field name authorisation having length 150 chars.

I want query to check authorisation at particular digit.

SELECT e.staffid, COUNT(e.staffid) FROM enrll e INNER JOIN staff s on e.staffid=s.staffid 
                        WHERE s.auth = '1' and NOT EXISTS (SELECT staffid FROM shdl h where s.staffid=h.staffid and h.shdldt='$unixdt')
                        GROUP BY e.staffid ORDER BY COUNT(e.staffid) DESC";

THough I have used a "1" for testing purpose but now I want to check auth at particular digit like. for that I took variable with 150 digit. I need to check at 150th position that if at last position it is 1 it will fetch record.

Upvotes: 1

Views: 73

Answers (2)

Andrej
Andrej

Reputation: 7504

May be you can try

substr(s.auth,-1) = '1'

Upvotes: 1

Jacob
Jacob

Reputation: 43209

... WHERE SUBSTRING(s.auth,150,1) = '1' ...

SUBSTRING(str, pos, len) can be used for this, but all your index on s.auth is useless then.

Upvotes: 1

Related Questions