Recently I found 2 useful SQL functions and would like to
share with you.
This function is quite useful for a
DBA.
For example:
DECLARE @Object varchar(100)
SELECT @Object = 'Mem.dbo.Member'
SELECT
PARSENAME (@Object ,3),
PARSENAME (@Object ,2),
PARSENAME (@Object ,1)
You could also apply the same
concept to e.g. split IP format
For example: instead of using
complex charindex
DECLARE @IP char(15)
SELECT @IP = '192.168.3.11'
SELECT
PARSENAME (@IP ,4),
PARSENAME (@IP ,3),
PARSENAME (@IP ,2),
PARSENAME (@IP ,1)
What it does is returning the first
non-null argument. It is equivalent to CASE
CASE
WHEN
(expression1 IS NOT NULL) THEN expression1
WHEN
(expression2 IS NOT NULL) THEN expression2
...
ELSE
expression
END
No comments:
Post a Comment