How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.
Do more with
select max(case when row_num = 1 then Value end col1
, max(case when row_num = 2 then Value end col2
, max(case when row_num = 3 then Value end col3
, max(case when row_num = 4 then Value end col4
--- etc ---
from dbo.ParmsToList('WRKP-PRNT-WNDW', '-') f
/*@InputString='WRKP-PRNT-WNDW-abc-def'
@delimiterString = '-'
@Index = 0 will return WRKP
@Index = 1 will return PRNT
..
..
otherwise it will return
*/
CREATE FUNCTION [dbo].[GetValueByIndex](@InputString varchar(8000), @delimiterString varchar(8000), @Index int) RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @OutputValue VARCHAR(8000)
SET @OutputValue = null
IF(@Index = 0)
BEGIN
IF(dbo.charindex2(@delimiterString,@InputString, 1) = 0)
SET @OutputValue = @InputString
ELSE IF( dbo.charindex2(@delimiterString,@InputString, 1) > 0)
SET @OutputValue = SUBSTRING(@InputString, 1, dbo.charindex2(@delimiterString,@InputString, 1) - 1 )
END
ELSE
BEGIN
IF (dbo.charindex2(@delimiterString,@InputString, @Index) > 0 AND dbo.charindex2(@delimiterString,@InputString, @Index+1) = 0)
SET @OutputValue =SUBSTRING(@InputString, dbo.CHARINDEX2(@delimiterString,@InputString, @Index) + 1, LEN(@InputString) )
ELSE IF ( dbo.charindex2(@delimiterString,@InputString, @Index+1) > 0)
SET @OutputValue =SUBSTRING(@InputString, dbo.CHARINDEX2(@delimiterString,@InputString, @Index) +1, dbo.CHARINDEX2(@delimiterString,@InputString, @Index+1) -dbo.CHARINDEX2(@delimiterString,@InputString, @Index)-1 )
END
RETURN(@OutputValue)
END
create FUNCTION [dbo].[CHARINDEX2](@TargetStr varchar(8000), @SearchedStr varchar(8000), @Occurrence int) RETURNS int
AS
BEGIN
DECLARE @pos int, @counter int, @ret INT
SET @ret = 1
SET @pos = CHARINDEX(@TargetStr, @SearchedStr)
SET @counter = 1
IF @Occurrence = 1 SET @ret = @pos
ELSE
BEGIN
WHILE (@counter < @Occurrence AND @ret > 0)
BEGIN
SELECT @ret = CHARINDEX(@TargetStr, @SearchedStr, @pos + 1)
SET @counter = @counter + 1
SET @pos = @ret
END
END
RETURN(@ret)
END
SELECT PARSENAME(REPLACE(a.probcode, '-', '.'), 3),
PARSENAME(REPLACE(a.probcode, '-', '.'), 2),
PARSENAME(REPLACE(a.probcode, '-', '.'), 1)
Premium Content
You need an Expert Office subscription to comment.Start Free Trial