Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,

I have searched enough on internet but could not get a result of what i am looking for.

My concern is that Is there any way to make a query in SQL and let sql execute it itself
and when ever i want result some how i could get result in Stored Procedure with out running it at that time.

E.G.: Lets say I want count of all rows from ABC table

so somewhere i want to write a query
Select count(*) From ABC


and then in stored proc i want latest count of table rows without running this query at that time. when i am running queries in my Stored Proc.

Thanks in Advance

Wishing you very happy new year....
Posted
Comments
Thanks7872 31-Dec-14 1:21am    
Why not to run that query inside the procedure? You want to get LATEST records,than you should execute query at the time when you execute the procedure. Further, if you want to do it anyhow, you have to store the result somewhere in database.
[no name] 31-Dec-14 1:23am    
If you don't want to run the query each time then how is it possible to get the exact data each time. Lets say I am running the stored procedure for the first time and I am having the record set as 10. After my query run the result will be 10 records in the table. If any records inserted in between then I will loose that count value. So its not a good idea to keep the count value in the global manner you want. Can you tell me why you need this kind of requirement.

1 solution

Hi,

If you want pre-calculated result is SQL Server, you are not in OLTP model, but you are using OLAP (Data Warehousing).

The only pre-calculated result is in DMV views (for OLTP Database)
http://msdn.microsoft.com/en-us/library/ms188754.aspx[^]

For table count rows you can use :
select rows from sys.partitions where object_name(object_id) = 'ABC'


You can use also new feature in SQL Server for OLTP called 'StreamInsight'
http://technet.microsoft.com/fr-fr/library/ee362541%28v=sql.111%29.aspx[^]

This feature allows raising call back event to the ASP client(Using SingalR), when your enumerated conditions is true.

Hope that help,
Béchir.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900