Convert MySQL query to Microsoft SQL Server
NickName:user1288792 Ask DateTime:2013-04-13T03:54:25

Convert MySQL query to Microsoft SQL Server

I need to convert this MySQL query to a SQL Server query where the syntax 'LIMIT ?, ?' is my main main problem because isn't compatible with SQL Server.

At the same time I don't know the meaning of the clause at the end SELECT FOUND_ROW().

I am beginner with databases so I would appreciate any assistance.

SELECT SQL_CALC_FOUND_ROWS TITLE, URL FROM SITE WHERE CITY='Berlin' LIMIT ?, ?

...

stmt.setInt(1, offset);
stmt.setInt(2, numRecords);

...

rs = stmt.executeQuery("SELECT FOUND_ROWS()");
if (rs.next())
this.noOfRecords = rs.getInt(1);

...

Copyright Notice:Content Author:「user1288792」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15979814/convert-mysql-query-to-microsoft-sql-server

Answers
Ed Gibbs 2013-04-12T20:25:27

If the MySQL is:\n\nSELECT URL\n FROM SITE\n WHERE CITY='Berlin'\n LIMIT 30, 20\n\n\nThen it's returning rows 31 through 50. In SQL Server you can do something like this:\n\nWITH somerows AS (\n SELECT TOP 50 URL, ROW_NUMBER() OVER (ORDER BY URL) AS SeqValue\n FROM SITE\n WHERE CITY='Berlin'\n)\nSELECT * FROM somerows\nWHERE SeqValue BETWEEN 31 and 50\n\n\nNote that the 50 in the SQL Server query is the sum of the MySQL LIMIT values, and that the 30 in MySQL is zero-indexed so it becomes 31 in SQL Server, where the ROW_NUMBER counter is one-indexed. Many thanks to Kevin Suchlicki for pointing this out in the comments below.\n\nAlso note that, unlike your MySQL query, you have to order the rows with the SQL Server query.\n\nFinally, SQL_CALC_FOUND_ROWS is a MySQL keyword that enables the FOUND_ROWS() function. It's explained in the documentation. There's no SQL Server equivalent. You'll need to count the rows some other way to set this.noOfRecords in your code, but you should be able to work around that.",


More about “Convert MySQL query to Microsoft SQL Server” related questions

How to convert this Microsoft SQL query into a MySQL query?

I used this query to get particular result from a Microsoft SQL Server table, but now I need to convert this query into MySQL query. I don't know how to do that. SELECT TOP 3 COUNT(Item1) AS ITEM_...

Show Detail

Convert MySQL query to Microsoft SQL Server

I need to convert this MySQL query to a SQL Server query where the syntax 'LIMIT ?, ?' is my main main problem because isn't compatible with SQL Server. At the same time I don't know the meaning ...

Show Detail

How to Convert SQL Server Query to MySQL Query

I'm trying to convert this SQL Server query to MySQL query how can i do that? Fallowing is my SQL server query. I need to convert this query to execute in MySQL. EpfNO is the Primary key and IsVali...

Show Detail

convert mysql query to sql server query

I want to convert below mysql query to sql query.I want to use If condition in sql server SELECT foodName, IF( foodPrice>2000, 'Expensive', 'Cheap') as fpDesc, discountPercent FROM restaurant.f...

Show Detail

Convert query from MySQL to SQL Server

I am trying to convert below MySQL query to SQL Server. SELECT @a:= @a + 1 serial_number, a.id, a.file_assign_count FROM usermaster a, workgroup_master b, ( SELECT @a: = 0...

Show Detail

Convert MySql query into MSSql query

Here is my MYSQL query and I want to convert this into MSSQL. I saw some answers to do that using Microsoft SQL Server Migration Assistant for MySQL. But since my PC is having some issues with

Show Detail

Conversion from Microsoft SQL Server to MySQL

How do I convert a Microsoft SQL Server database backup file such that to import in MySQL database? Is there any way or free tool available for this?

Show Detail

Microsoft SQL Server equivalent of MySQL REGEXP

I am trying to reconstruct a database query I created for MySQL in Microsoft SQL Server. I am looking for an operator or function SQL Server which acts like REGEXP. Here is an example of how I am ...

Show Detail

how to convert mysql queries to microsoft sql query

I have some MySQL queries that I want to transform to MS SQL. $result_of_sql_query = mysql_query( $settings['query'] , $settings['connect'] ); How do I transform this to MS SQL Server query.

Show Detail

Convert Sql Server Query to MySql Server Query

Good Morning I am Trying to Convert Sqlserver Join to Mysql server Join , Anyone please help me on this Sql Server Code Update @ABC Set grpId = g.GroupId From @ABC, luGroup g Where typ...

Show Detail