1

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.

2 Answers 2

1
... 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.

Sign up to request clarification or add additional context in comments.

5 Comments

Substring is not a sql function than how can I use it with above code. Can you please rewrite the code.
Substring is a MySQL function, just replace your WHERE s.auth = '1' with the code in my answer.
OK.. what will happen if I use negative value like substr(s.auth,-1) = '1'
-1 means get the last char, 150 just means get the 150th char. They are equivalent, if you have fixed size of 150 chars.
But if not you will get empty string.
1

May be you can try

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

1 Comment

You can check working via query select substr('Testing',-1); Result is g.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.