Friday
Oct162009
Split full db object names into parts with a little help from a friend
Friday, October 16, 2009 at 2:01PM
so you have a string in T-SQL such as:
MyProdSvr.ReallyGoodDB.SomeSchema.MyFavoriteTable
Woldn't it be nice if there was an easy mecanism to crack that code.
Try This:
DECLARE @MyObjectFullName sysname SET @MyObjectFullName = 'MyProdSvr.ReallyGoodDB.SomeSchema.MyFavoriteTable' SELECT PARSENAME(@MyObjectFullName, 4) AS ServerName , PARSENAME(@MyObjectFullName, 3) AS dbName , PARSENAME(@MyObjectFullName, 2) AS SchemaName , PARSENAME(@MyObjectFullName, 1) AS ObjectName
 
ServerName | dbName | SchemaName | ObjectName |
MyProdSvr | ReallyGoodDB | SomeSchema | MyFavoriteTable |
 
{Thanks Chuck}
Reader Comments