Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL-CURSOR QUERY

Author  Topic 

satya068
Posting Yak Master

233 Posts

Posted - 2010-03-17 : 18:39:22
Hi..
could anyone help in this query?

In my database TABLE1 has 2 columns which contais all the table_names n row count in the database.

these are all the sys.tables n sys.indexes table_names and row count inserted into TABLE1.

Now i want to get a new column INSERT_DATE_COUNT>=sysdate() to all the tables in in TABLE1.

INSERT_DATE_COUNT is nothing but count for INSERT_DATE column which already exists in all the tables in the same database.

now my final table should exists TABLE_NAME,ROW_COUNT AND INSERT_DATE_COUNT.

when i run the query i need all the count for insert_date>=sysdate().

thnax for your help



Satya

yashu

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-18 : 02:51:32
Execute this query and remove last union all from the result then execute the result
you will get the table names with count

SELECT 'SELECT ''' + Name + ''' [TableName], COUNT(*) [Count] FROM ' + Name + 'WHERE Insert_Date >= GETDATE() UNION ALL' FROM sys.tables


this is what i understood. if any thing else let me know.


Vaibhav T
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-18 : 03:38:13
Refer this
http://beyondrelational.com/blogs/madhivanan/archive/2007/11/02/different-ways-to-count-rows-from-a-table.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

satya068
Posting Yak Master

233 Posts

Posted - 2010-03-18 : 04:38:52
hi..

ill try ur with that query.

thanx for ur help.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-18 : 05:09:41
you are welcome

Vaibhav T
Go to Top of Page
   

- Advertisement -