在执行以下语句时,会为Start_Index
和End_index
返回非空/空值的混合值:
SELECT
CHARINDEX('_', dbo.Components.Cast, 1) AS Start_Index,
CHARINDEX('_', dbo.Components.Cast, CHARINDEX('_', dbo.Components.Cast, 1) + 1) AS End_Index
FROM dbo.Components
由于我希望同时执行赋值和数据检索,因此我将SELECT
语句分为两部分。但是,Start_Index
和End_index
现在为所有行返回NULL
:
DECLARE @start_index INT
DECLARE @end_index INT
SELECT
@start_index = CHARINDEX('_', dbo.Components.Cast, 1),
@end_index = CHARINDEX('_', dbo.Components.Cast, CHARINDEX('_', dbo.Components.Cast, 1) + 1)
FROM dbo.Components
SELECT
@start_index AS Start_Index,
@end_index AS End_Index
FROM dbo.Components
我在做什么错了?