I have a string in the format . (eg 902.5)
Need to split and collect this into separate variables in sql server 2008.
DECLARE
@Core VARCHAR(10)='902.5',
@OrgNumber VARCHAR(6) = NULL,
@DeptNumber VARCHAR(2) = NULL
IF (NULLIF(@Core, '')) IS NOT NULL
BEGIN
SELECT @OrgNumber =SUBSTRING(@Core, 1, CHARINDEX('.', @Core) - 1),
@DeptNumber =SUBSTRING(@Core, CHARINDEX('.', @Core) + 1, LEN(@Core))
SELECT @OrgNumber = upper(nullif(ltrim(nullif(rtrim(@OrgNumber ), '')), '')),
@DeptNumber = nullif(ltrim(nullif(rtrim(@DeptNumber ), '')), '')
END
However this does not handle the case where Contains the Org ref only(no dept ref) e.g 902
How do I handle the case gracefully within the same statement?