开发者

SQL Server - CHARINDEX always returns 0

开发者 https://www.devze.com 2022-12-20 12:18 出处:网络
I have the following query: SELECT CAST([Action] AS NVARCHAR(4000)) AS CastAction, CHARINDEX(CAST([Action] AS NVARCHAR(4000)), N\'StatusChange\') AS FoundI开发者_StackOverflow中文版ndex

I have the following query:

SELECT 
   CAST([Action] AS NVARCHAR(4000)) AS CastAction, 
   CHARINDEX(CAST([Action] AS NVARCHAR(4000)), N'StatusChange') AS FoundI开发者_StackOverflow中文版ndex
FROM AuditTrail 
WHERE action LIKE '%StatusChange%'

Action is an NTEXT field - this query returns many rows, matching StatusChange in the action text, but the charindex returned is always zero... Any ideas - I need to be able to split this string to tidy up some data?


You've got the parameters to CHARINDEX the wrong way around.


You're swapping parameters:

Searches expression2 for expression1 and returns its starting position if found.

Try:

CHARINDEX(N'StatusChange', CAST([Action] AS NVARCHAR(4000)))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号