2

If i have employee_id with integer (like 1001) alone, am getting the answer

example the code like this ,

   $claimprocess = Employee::find()
                    ->where("employee_id = '1004'  and importcompany_id = 1")
                    ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                    ->all();

if i have a employee_id with combination interger and character, am not able get a answer(like E1004),

example code like below,

$claimprocess = Employee::find()
                    ->where("employee_id = 'E1004'  and importcompany_id = 1")
                    ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                    ->all();

When I execute this code, am getting error like below

Exception (Database Exception) 'yii\db\Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Champ 'E1004' inconnu dans where clause The SQL being executed was: SELECT * FROM employee WHERE (employee_id = E1004 and importcompany_id = 1) AND ( status != 'Deleted' )'

UPDATED:

actually am getting that value(E1004) from another variable, I use the variable instead of value, for understanding purpose I have used a value there in my question

1
  • 1
    employee_id = E1004 it need to be employee_id = 'E1004' Commented Aug 10, 2015 at 7:12

3 Answers 3

3

You need to enclose your employee_id value i.e. E1004 within quotes its because it contains string literals. So your query looks like a

->where("employee_id = 'E1004'  and importcompany_id = 1")
Sign up to request clarification or add additional context in comments.

2 Comments

actually am getting that value from another variable, i use the variable instead of value, for understanding purpose i have used a value there in my question
So enclose that variable along with quotes then
1

String literals in SQL are denoted with single quotes ('). Without them, the database would interpret E1004 as a column name, and fail the query, since your table doesn't have such a query.

$claimprocess = Employee::find()
                ->where("employee_id = 'E1004'  and importcompany_id = 1")
                ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                ->all();

Comments

0

You need to pass the value correctly , as if now you are not passing the value correctly , hence Yii is not generating Sql query correctly. You can pass second parameter to to where clause

    $claimprocess = Employee::find()
                        ->where("employee_id = ':employee_id'  and importcompany_id = 1" , array(':employee_id'=>'E1004'))
                        ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                        ->all();

5 Comments

Actually am passing literal value, i have a variable that contains value like 1003, E1004. i understanding purpose i have used value instead of variable
i have use like this $claimprocess = Employee::find() ->where("employee_id = $employee_id and importcompany_id = 1") ->andwhere(" status != 'Deleted' and relationship = 'Self'") ->all();
->where("employee_id = ':employee_id' and importcompany_id = 1" , array(':employee_id'=>$valueVariable))
try like this $claimprocess = Employee::find() ->where("employee_id = '$employee_id' and importcompany_id = 1") ->andwhere(" status != 'Deleted' and relationship = 'Self'") ->all();
great :) , sometime we forget the basics

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.