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 1096793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:19:58+00:00 2026-05-17T00:19:58+00:00

I have declared a Cursor to get table names and no of columns in

  • 0

I have declared a Cursor to get table names and no of columns in that tables based on column names.Please find the below query table name is not get inserted.Please suggest.

Create table #t
(
tabname varchar(500),
NoOfRows bigint,
)

Declare @Namee Varchar(500)
Declare @GetName Cursor
Set     @Getname = Cursor for 
Select table_name from information_Schema.columns
where column_name='isactive'Open @Getname
Fetch Next From @Getname into @Namee
While @@Fetch_Status=0
Begin 
--Print @Namee
insert into #t(tabname) SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE  TABLE_NAME =' + @Namee + '
exec ('insert into #t(NoOfRows)  Select count(*) from ' + @Namee + ' where isactive=0')
Fetch Next From @Getname into @Namee
End
Close @GetName
Deallocate @GetName
select * from #t 
  • 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-05-17T00:19:59+00:00Added an answer on May 17, 2026 at 12:19 am

    You can insert the table name and number of rows in a single INSERT:

    EXEC('INSERT INTO #t
             (tabname, NoOfRows)  
          SELECT '''+ @Namee +''', COUNT(*) 
            FROM ' + @Namee + ' 
           WHERE isactive = 0')
    

    What you have makes no link between the table name and the count, so it’s unlikely you’re missing a table but it is doubtful that the NoOfRows was actually associated with the table name in the record.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With sql Server 2005. I have declared a trigger that get fired AFTER INSERT,
How to get result in WITH table AS into CURSOR loop? I have previously
I have a table (MySQL) that has a column called binID. The values in
I have a table in SQL Server 2005 with a variable number of columns,
I have a table variable that is being passed into a procedure. I would
I have a table with start and finish datetimes that I need to determine
I have a table that has some children of a master object. Any child
Very simplified, I have two tables Source and Target. declare @Source table (SourceID int
I have a stored procedure in MySQL that should update a column in a
Description: the query actually run have 4 results returned,as can be see from below,

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.