Feeds:
Posts
Comments

Posts Tagged ‘len’

DECLARE @passed VARCHAR(max)

SET @passed = 'FirstBit exec dbo.usp_Sites 4'

PRINT substring(@passed, 1, -- Change 1 to the vlaue you want the extraction to start from
		patindex('% exec %', @passed) - 1 -- Chage " exec " to any value in the string till which you want it extracted
	)
PRINT substring(@passed, patindex('% exec %', @passed) + 1, len(@passed) - patindex('% exec %', @passed))

-- The function Left() and Right() are also used when you want the extraction to start from either
-- left most or right most side.
-- To extract certain characters from a string using charindex
DECLARE @find AS VARCHAR(max)

SET @find = 'dbo'

PRINT substring(@passed, charindex(@find, @passed), len(@find))
-- Patindex could also have been used above but ii used the format >> '% [this is where your txet goes]  %' )
---Difference in patindex() and charindex()
PRINT patindex('%' + @find + '%', @passed)
PRINT charindex(@find, @passed)


Read Full Post »