I have this mssql query:
with RESULT as(select TITLE, URL, ROW_NUMBER() over (order by URL) as SeqValue from WEBSITE
select * from RESULT where SeqValue>=20 and SeqValue<=40
I'd like to know how many record this query would return if the where statement was not there.
I try with select count(*) from RESULT
and try with @@ROWCOUNT
and many others way but did not work.
I need TITLE and URL from select, and in the end i need total record for the select.
For example in mysql query i have prepareStatement using SQL_CALC_FOUND_ROWS
:
select SQL_CALC_FOUND_ROWS TITLE, URL from WEBSITE limit ?, ?
and after this select i have:
select FOUND_ROWS()
In this example returned value is total record for the mysql query. Total record is same with LIMIT and without LIMIT directive. I convert database from mysql to mssql and i have problem with this. Please help me...
F1. When writing a query with SQL_CALC_FOUND_ROWS or FOUND_ROWS(), there should be a warning (both with the standard deprecation warning code 1287): Warning 1287 SQL_CALC_FOUND_ROWS is deprecated and will be removed in a future release. Consider using two separate queries instead.
SQL_CALC_FOUND_ROWS and FOUND_ROWS() can be useful in situations when you want to restrict the number of rows that a query returns, but also determine the number of rows in the full result set without running the query again.
ROW_COUNT() returns the number of rows updated, inserted or deleted by the preceding statement. This is the same as the row count that the mysql client displays and the value from the mysql_affected_rows() C API function.
The SQL BETWEEN Operator The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.
I had the same concern when trying to move from MySQL to SQL SERVER the solution is to inject this in your query:
COUNT (*) OVER () AS ROW_COUNT
ROWCOUNT appear in all rows in the result then it only remains for you to retrieve ROW_COUNT from the first row result (if exists) and not forget to reset the result pointer et Voila;-).
for example:
select COUNT (*) OVER () AS ROW_COUNT, URL from WEBSITE limit ?, ?
I hope it will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With