Click to See Complete Forum and Search --> : MySql -> MSSQL Conversion


quadoc
04-30-2008, 02:21 PM
Could someone give me the equivalent in MSSQL to the following MySql statement. :confused: Thanks...


$sql = "SELECT * FROM ".DB_TABLENAME." ".$filter_str." ".($this->OrderBy?" ORDER by ".$this->OrderBy["field"]." ".$this->OrderBy["direction"]:"")." LIMIT {$this->Offset},{$this->Limit}";

chazzy
04-30-2008, 02:43 PM
the only difference is that you need to use TOP instead of LIMIT to limit the # of results. to do an offset, you should use row_number. see this example:

http://www.singingeels.com/Articles/Pagination_In_SQL_Server_2005.aspx

quadoc
05-01-2008, 12:58 PM
Ok, I tried with the following codes and it gave me an error. Does anyone have any tips? :confused: Thanks....


$sql = "SELECT TOP ".$this->Limit." * FROM ".DB_TABLENAME." WHERE ticket_ID NOT IN (SELECT TOP ".$this->Offset." ticket_ID from ".DB_TABLENAME.$filter_str." ".($this->OrderBy?" ORDER by ".$this->OrderBy["field"]." ".$this->OrderBy["direction"]:"").($this->OrderBy?" ORDER by ".$this->OrderBy["field"]." ".$this->OrderBy["direction"]:"");

chazzy
05-01-2008, 01:29 PM
why do you have 2 order bys?