Avatar of urjudo
Flag for United States of America

asked on 

SQL subquery in Main query

Hi experts,
I have a SQL query question.
I need to create a query for Search purpose.  I have a table named Empl, it's an Employee table, it has Empl_LN, Empl_FN, Empl_Add, I want like to have an alias name for Emloyee name, and I would like to use the Employee name for LIKE operator to search.  I know I have to create a subquey for the Employee name because if I just create in the main query, the Employee name is an alias name but it doesn't have the table name in the query.  

Here is my query:
SELECT EmplNo, Empl_LN, Empl_FN,
    (SELECT Empl_LN + ', ' + Empl_FN AS EmployeeName
        FROM EMPL)
WHERE EmployeeName LIKE ?
Order By Empl_LN

It gave me an error message.  I couldn't figure it out.  any help will be very appreciated!

Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon