Welcome Guest, Not a member yet? Register   Sign In
ORDER BY QUERY BUILDER ISSUE
#1

(This post was last modified: 01-23-2016, 02:03 AM by mertdogan.)

I hava a test query :
Code:
$this->db->where('1 IS NOT NULL',NULL,FALSE)->WHERE('X>','0')->FROM('X')->ORDER_BY('X','ASC')->count_all_results();

and it is generating error:

Code:
Error Number: 42000/1033

[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.

SELECT COUNT(*) AS "numrows" FROM ( SELECT * FROM "X" WHERE 1 IS NOT NULL AND "X" > '0' ORDER BY "X" ASC ) CI_count_all_results
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#2

Why are you doing ORDER BY clause if you just need to get the number of records?! Just remove it.
Reply
#3

The error is coming from SQL Server, not from Query Builder. As siburny said, you need to take out the order_by clause in your query. In most cases, Query Builder isn't going to check whether the particular combination of SQL commands you've specified is permitted by your platform; it will let the database server produce an error, as it has in this case.
Reply
#4

https://github.com/bcit-ci/CodeIgniter/issues/4395

It'd be much less time-wasting for everybody if people didn't cross-post.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB