C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Count record from the multiple tables


Posted Date: 14 Aug 2008    Resource Type: Code Snippets    Category: SQL
Author: vipulMember Level: Diamond    
Rating: Points: 10



Hi,
I am create a sql query for using this query you can find particular records in how many table and how much?

In this you pass your column name and record
'name' = put your column name
'XMas' = put your record which you find



declare @tablename varchar(500)
declare @colname varchar(500)

CREATE TABLE #t(tablen varchar(500),countrecord int)

DECLARE RuleList CURSOR FOR
select tab.name,col.name from sys.all_columns col
left outer join sys.tables tab on tab.object_id = col.object_id
where col.name = 'name' and tab.name is not null
OPEN RuleList
FETCH NEXT FROM RuleList into @tablename,@colname
WHILE (@@FETCH_STATUS = 0)
begin
declare @Sql nvarchar(2000)
set @Sql = 'INSERT INTO #t select '''+ @tablename + ''' , count(*) from ' + @tablename + ' where ' + @colname + ' = ''XMas'''
--print @Sql
execute sp_ExecuteSql @SQL
FETCH NEXT FROM RuleList into @tablename,@colname
end
select tablen, countrecord from #t where countrecord <> 0
drop table #t
CLOSE RuleList
DEALLOCATE RuleList





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
SQL query  .  Count record query  .  Count record from the multipal tables  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Delete Duplicate Records in Sql Server 2000
Previous Resource: PIVOT Operator in SQL Server 2005
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use