开发者

SQL Server - CHARINDEX always returns 0

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜