November 9, 2021 at 10:24 am
I would like to know the base object that is used in the synonyms, so there is a column called base_object_name:
- The table is use is (
SELECT base_object_name
FROM sys.synonyms
)
Is there someone who is able to sepereate the value in the columns?
I would like the value [db].[dbo].
in seperate column.
Need some help?
November 9, 2021 at 10:33 am
Easy. Use PARSENAME():
SELECT base_object_name
,CONCAT(QUOTENAME(PARSENAME(base_object_name, 3)), '.', QUOTENAME(PARSENAME(base_object_name, 2)))
FROM sys.synonyms;
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 9, 2021 at 12:55 pm
That not really the solution, but I have something but not complete:
SELECT DISTINCT [name] AS SYN_NAME,
LEFT (REPLACE(REPLACE(base_object_name ,'[',''),']',''),
CHARINDEX('.', REPLACE(REPLACE(base_object_name ,'[',''),']',''))-1) AS DBNM,
(LEFT (REPLACE(REPLACE(base_object_name ,'[',''),']',''),
CHARINDEX('.', REPLACE(REPLACE(base_object_name ,'[',''),']',''))-1)) AS DBID,
RIGHT (REPLACE(REPLACE(base_object_name ,'[',''),']',''),
CHARINDEX('.', reverse(REPLACE(REPLACE(base_object_name ,'[',''),']','')))-1) AS objectname
FROM sys.synonyms
The only think that needs CHANGE is the middle part DBID must be my SCHEMANAME 🙂
November 9, 2021 at 1:02 pm
Please explain why it's "not really the solution".
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 9, 2021 at 1:18 pm
O srry, because I would like erverthing in seperate column:
dbname | schema | Table/view |
db dbo xxxx
🙂
November 9, 2021 at 1:47 pm
SELECT base_object_name
,DBName = PARSENAME(base_object_name, 3)
,SchemaName = PARSENAME(base_object_name, 2)
,ObjectName = PARSENAME(base_object_name, 1)
FROM sys.synonyms;
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply