Using X at the end of a SELECT in SQL Server Script?
The "X" is an alias for the following portion:

Select distinct roleid 
from UserAccounts 
WHERE CustID = @custID


So you'd be able to use it as:

SELECT x.roleid
FROM  
(    Select distinct roleid 
from UserAccounts 
WHERE CustID = @custID) x
where x.roleid &gt;100


In the grand scheme of things, your query would look like:

 (select @invtid = coalesce(@invtid + ',',' ')+rtrim(x.RoleID) 
 FROM (
    Select distinct roleid 
    from UserAccounts 
    WHERE CustID = @custID
     )x
 )


technically you can use anything as your Alias.  "X", usually a more descriptive alias works.  Something like "roles"