Home > front end >  Get table name without schema
Get table name without schema

Time:12-14

There is a string that could be a table name with ANY schema, not necessarily dbo. How do I get the table name only from the string without knowing the schema? E.g. from 'dbo.MyTable' I would need to extract 'MyTable'.

CodePudding user response:

PARSENAME can be used for this:

SELECT PARSENAME ('server.database.dbo.object', 1) -- object
SELECT PARSENAME ('database..object', 1)           -- object
SELECT PARSENAME ('object', 1)                     -- object
SELECT PARSENAME ('[foo bar]', 1)                  -- foo bar
  • Related