Domanda

If i have query like this ::

 SELECT a.emp_num, a.emp_num ||'-'|| a.name AS emp_name
 FROM Employees a 
 WHERE emp_name LIKE '' //Error

How to filter based on emp_name instead of name

È stato utile?

Soluzione

You can wrap your query in another SELECT and use alias from emp_name the first SELECT as a field name in it :

SELECT x.* 
FROM (SELECT a.emp_num
           , a.emp_num ||'-'|| a.name AS emp_name
      FROM Employees a 
) x
WHERE x.emp_name LIKE '' 

If you don't want to use a subsidiary outer SELECT then you can just pass the whole concatenated string in you WHERE clause :

SELECT a.emp_num
     , a.emp_num ||'-'|| a.name AS emp_name
FROM Employees a 
WHERE a.emp_num ||'-'|| a.name LIKE ''
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top