How do you get the domain name that your SQL Server machine belongs to with T-SQL code?
You can use the undocumented procedure xp_regread; I have tested this on SQL Server 2005 and on SQL Server 2000.
Be advised that since this is an undocumented procedure that it might not be available in the future or it might be changed either because of a service pack or a hot fix. Don't use it as production code!
Here is how to do this
DECLARE @chvDomainName NVARCHAR(100)
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
SELECT @chvDomainName AS DomainName