web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to get a row count for all tables in sql for specific company in ax 2012

(0) ShareShare
ReportReport
Posted on by

Hi,

I want to get row count for all the tables that are present in the sql for specific company let's say for tb00.

how can i fetch the correct results

*This post is locked for comments

I have the same question (0)
  • Bilal Issa Profile Picture
    4,370 on at

    CREATE TABLE #counts ( table_name varchar(255), row_count int ) EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ? where DataAreaId = CompanyId' SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC

  • Suggested answer
    Florian Hopfner Profile Picture
    2,461 on at

    Tools > Number of records

    Strg+T

    get coffee

    filter by Company

  • Community Member Profile Picture
    on at

    I am getting error like CompanyId not found. If i am giving companyId as TB00 then its saying TB00 is a invalid column name. How can i over come this.

  • Verified answer
    Community Member Profile Picture
    on at

    DECLARE @QueryString NVARCHAR(MAX) ;

    SELECT @QueryString = COALESCE(@QueryString + ' UNION ALL ','')

                         + 'SELECT '

                         + '''' + QUOTENAME(SCHEMA_NAME(sOBJ.schema_id))

                         + '.' + QUOTENAME(sOBJ.name) + '''' + ' AS [TableName]

                         , COUNT(*) AS [RowCount] FROM '

                         + QUOTENAME(SCHEMA_NAME(sOBJ.schema_id))

                         + '.' + QUOTENAME(sOBJ.name) + ' WITH (NOLOCK) '

    FROM sys.objects AS sOBJ

    WHERE

         sOBJ.type = 'U'

         AND sOBJ.is_ms_shipped = 0x0

    ORDER BY SCHEMA_NAME(sOBJ.schema_id), sOBJ.name ;

    EXEC sp_executesql @QueryString

    This query helped me to fetch the desired results.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans