Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 子字符串_索引'错误_Mysql_Sql_Sql Server - Fatal编程技术网

Mysql 子字符串_索引'错误

Mysql 子字符串_索引'错误,mysql,sql,sql-server,Mysql,Sql,Sql Server,此代码在MySQL中执行良好: SELECT SUBSTRING_INDEX(empid, '-', 1) FROM employees 但它会在SQL Server中引发以下错误: “SUBSTRING_INDEX”不是可识别的内置函数名 我不想使用where子句。在SQL Server中,您可以执行以下操作: select (case when empid like '%-%' then left(empid, charindex('-', empid) - 1

此代码在MySQL中执行良好:

SELECT SUBSTRING_INDEX(empid, '-', 1) 
FROM employees
但它会在SQL Server中引发以下错误:

“SUBSTRING_INDEX”不是可识别的内置函数名


我不想使用where子句。

在SQL Server中,您可以执行以下操作:

select (case when empid like '%-%'
             then left(empid, charindex('-', empid) - 1)
             else empid
        end)
from employees;

错误是不言自明的,子字符串索引不是SQL Server中的内置函数。您的问题是什么?我如何修改查询以在MS SQL Server中使用它?对于此特定示例,您可以使用类似以下内容:从employees中选择LEFTempid、CHARINDEX'-',empid、1-1-这与子字符串索引不太相似,因此是一条注释而不是答案,但它应该适用于您的情况。我收到以下错误:传递给LEFT或SUBSTRING函数的长度参数无效。现在收到以下错误:传递给LEFT或SUBSTRING函数的长度参数无效。