This code is executing fine in MySQL :
SELECT SUBSTRING_INDEX(empid, '-', 1)
FROM employees
But it throws this error in SQL Server :
'SUBSTRING_INDEX' is not a recognized built-in function name.
I don't want to use where clause.
This code is executing fine in MySQL :
SELECT SUBSTRING_INDEX(empid, '-', 1)
FROM employees
But it throws this error in SQL Server :
'SUBSTRING_INDEX' is not a recognized built-in function name.
I don't want to use where clause.
In SQL Server, you can do:
select (case when empid like '%-%'
then left(empid, charindex('-', empid) - 1)
else empid
end)
from employees;