1

I have a big select with many inner join and left join and select to select like:

SELECT 
    ( ... ) 
ORDER BY 
    Price 

The question is for count of select am I must to run this select again ?

SELECT    
    COUNT( ... )  
ORDER BY 
    Price 

Is there any easy way to run one times and get result of select and count of select ?

Here is my C# code with Entity Framework:

string strQuery = "....";

IQueryable<ProductDto> list = _entities.Database.SqlQuery<ProductDto>(strQuery).AsQueryable();

2 Answers 2

3

You can use select @@rowcount to get the number of rows selected by the previous statement as a second resultset, or use SET @myOutputVar = @@ROWCOUNT it as an output parameter of your stored procedure.

A few Q/A's here on StackOverflow that may also help

Sign up to request clarification or add additional context in comments.

3 Comments

Can you show it on my query please , I didn't understand it
@dan - how do you execute your select is it a stored procedure? Is it called from .NET code?
@dan - have you seen this: CountAsync()
0

Yes you can try select @@rowcount.It Returns the number of rows affected by the last statement. If the number of rows is more than 2 billion, use ROWCOUNT_BIG.

https://msdn.microsoft.com/en-IN/library/ms187316.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.