Query

  • CREATE

    TABLE #tbls (

    tbl_name

    SYSNAME

    )

    exec

    sp_msforeachtable 'IF (SELECT COUNT(*) FROM ?) > 0 INSERT #tbls SELECT ''?'' '

    SELECT

    * FROM #tbls ORDER BY tbl_name

    when i use this query i get full table name like [empuser].[employees]

    how can i get just table name as employees

  • You can do a update before the select

    UPDATE

    #tbls SET tbl_name = REPLACE(tbl_name,'[empuser].','')

  • but still i cudnt replace [ ] for table name.

    I need just employees instead of [employees]

  • UPDATE

    #tbls SET tbl_name = REPLACE(REPLACE(REPLACE(tbl_name,'[empuser].',''),'[',''),']','')

     

  • SELECT O.Name

    FROM sysobjects O

    INNER JOIN sysindexes I ON I.ID = O.ID AND I.indid in (0, 1)

    WHERE O.xtype = 'U' AND I.rowcnt > 0

    BTW, you may have 2 or more tables with the same name but different owners.

    _____________
    Code for TallyGenerator

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply