SQL Function
create function fncGetDomain
(
@StringValue nvarchar(32)
)
Returns nvarchar(32)
AS
BEGIN
DECLARE @PositionIndexValue INT
DECLARE @StringLength INT
DECLARE @DotIndex INT
SET @PositionIndexValue = CHARINDEX('@',@StringValue)
SET @StringLength = LEN(@StringValue)
SET @StringValue = SUBSTRING(@StringValue,@PositionIndexValue+1,@StringLength-@PositionIndexValue)
SET @DotIndex = CHARINDEX('.',@StringValue)
return SUBSTRING(@StringValue,1,@DotIndex-1)
End
SQL StoredProcedure
CREATE proc uspGetDomain
(
@StringValue NVARCHAR(32)
)
AS
BEGIN
DECLARE @PositionIndexValue INT
DECLARE @StringLength INT
DECLARE @DotIndex INT
SET @PositionIndexValue = CHARINDEX('@',@StringValue)
SET @StringLength = LEN(@StringValue)
SET @StringValue = SUBSTRING(@StringValue,@PositionIndexValue+1,@StringLength-@PositionIndexValue)
SET @DotIndex = CHARINDEX('.',@StringValue)
SELECT SUBSTRING(@StringValue,1,@DotIndex-1)
END
By Stored Procedure
uspGetDomain '[email protected]'O/P: gmail
By function
SELECT dbo.fncGetDomain('[email protected]')O/P: gmail
