I would like to write a query using
IF(Emp.Name is not null)
((Emp.Name) + '_' + (Emp.LastName)) as ID
Incorrect syntax near the keyword 'IF'.
You can use
CASE EXPRESSION :
SELECT CASE WHEN emp.name is not null THEN emp.name + '_' + emp.lastName ELSE Emp.id END as [ID] FROM ...
IF() is performed differently in SQL-Server (I assume by the concat syntax),
IF ( Condition ) SQL STATEMENT ELSE SQL STATEMENT
Which means you need to perform the entire select in each block. Your kind of
IF() is used in MySQL ,
IF(Condition , THEN , ELSE )