From: Peso on
SELECT PARSENAME(REPLACE(@var, '@', '.'), 2) + '.' + PARSENAME(@var, 1)
SELECT SUBSTRING(@var, CHARINDEX('@', @var) + 1, 200)

//Peter


"VSLA" <VSLA(a)discussions.microsoft.com> wrote in message
news:6AA1700F-1EFE-4E6A-8B40-23F698DF7FF6(a)microsoft.com...
> I am trying to create a UDF to extract the domain name out of a full email
> address, as follows:
>
>
> CREATE FUNCTION dbo.udf_GetDomainName (@FullEmail VARCHAR(75))
> RETURNS Varchar(75)
>
> AS
>
> Begin
> DECLARE @domainname VARCHAR(75)
> Declare @delim CHAR(1)
>
> SET @delim = '@'
>
> SELECT @domainname = SUBSTRING(@domainname, 1, CHARINDEX(@delim,
> @domainname) - 1),
> SUBSTRING(@domainname, LEN(@domainname)+ 1 -
> CHARINDEX(@delim, REVERSE(@domainname)) + 1, LEN(@domainname))
> Return (@domainname)
> end
>
>
>
> I am getting the following error message:
>
> Msg 141, Level 15, State 1, Procedure udf_GetDomainName, Line 19
> A SELECT statement that assigns a value to a variable must not be combined
> with data-retrieval operations.
>
>
> Any thoughts?
> thanks,