Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:41:38+00:00 2026-06-11T01:41:38+00:00

I can get the row count of all tables using this query. SELECT ‘[‘

  • 0

I can get the row count of all tables using this query.

    SELECT '[' + SCHEMA_NAME(t.schema_id) + '].[' + t.name + ']' AS fulltable_name, SCHEMA_NAME(t.schema_id) AS schema_name, t.name AS table_name,
    i.rows
    FROM sys.tables AS t INNER JOIN
    sys.sysindexes AS i ON t.object_id = i.id AND i.indid < 2

**AND
t.name.programID = 4**

but I need to count all rows where programID = n
I keep getting the following error when adding the bolded line to the where clause

Cannot call methods on nvarchar.
Any help is greatly needed an appreciated
Andy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:41:39+00:00Added an answer on June 11, 2026 at 1:41 am

    The table name in your example can not be accessed like a property. It’s just a string and not the table itself. I’ve comprised a solution that may work for you. It feels a little like a hack, but It will get you on your way.

    DECLARE @Value INT, @Column_Name VARCHAR(MAX)
    
    SELECT @Value = 4, @Column_Name = 'ProgramId'
    
    IF OBJECT_ID(N'tempdb..#Results',N'U') IS NOT NULL
                DROP TABLE #Results
    
    SELECT  '[' + SCHEMA_NAME(t.schema_id) + '].[' + t.name + ']' AS fulltable_name, SCHEMA_NAME(t.schema_id) AS     schema_name, t.name AS table_name,
    i.rows [Row_Count]
    INTO #Results
    FROM sys.tables AS t INNER JOIN
    sys.sysindexes AS i ON t.object_id = i.id AND i.indid < 2
    INNER JOIN information_schema.COLUMNS  C ON t.name = c.TABLE_NAME AND SCHEMA_NAME(t.schema_id)= c.TABLE_SCHEMA  
    WHERE C.COLUMN_NAME = @Column_Name
    
    DECLARE @SQL VARCHAR(MAX)
    
    SELECT @SqL = COALESCE(@SqL +' UNION ',' ')  + 'SELECT '''+ fulltable_name + ''', COUNT(*) FROM ' +     fulltable_name +     ' where ' + @Column_Name + ' = ' + CAST(@Value AS VARCHAR(1000))+ ' GROUP BY ' + @Column_Name     + ' '
    FROM #Results
    
    PRINT(@SqL)
    EXEC (@SqL)
    
    IF OBJECT_ID(N'tempdb..#Results',N'U') IS NOT NULL
                DROP TABLE #Results
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can get the current selected row in this way: private void DataGridView1_CellContentClick(object sender,
How can I get the Nth row using Linq? both columns are text so
Can I run a select statement and get the row number if the items
I'm looking for a way to find the row count for all my tables
I need to get the row count of a query, and also get the
I can get the the first row in a ListView item in .NET 3.5
I can't get the table row to fade out in IE. It works in
How can I get DateTime value in C# from row, the current code is
How can I get the current selected row for UIPicker? I want to use
How can I get the previous version of data of a Row in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.