CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: SQL

Use PARSENAME to get the fully qualified object name

158 Views
Copy Code Show/Hide Line Numbers
DECLARE @str nvarchar(128)
SET @str = '[AdventureWorks].[dbo].[ErrorLog]'
 
SELECT    ISNULL(PARSENAME(@str, 4), @@SERVERNAME) AS [ServerName],
        ISNULL(PARSENAME(@str, 3), DB_NAME()) AS [DatabaseName],
        ISNULL(PARSENAME(@str, 2), ISNULL([default_schema_name], 'dbo')) AS [SchemaName],
        PARSENAME(@str, 1) AS [ObjectName]
       
FROM [sys].[database_principals]
WHERE [name] = SYSTEM_USER
       
by kopelli
  December 31, 2009 @ 6:32am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate