MySQL VS MsSQL Syntax | Code Factory

CREATE TABLE menu_master (
id int(11) NOT NULL,
menu_name varchar(45) NOT NULL,
menu_action varchar(45) NOT NULL,
parent_id int(11) NOT NULL,
menu_order int(11) DEFAULT NULL,
PRIMARY KEY (id)
)

MySQL

SELECT * FROM MENU_MASTER WHERE FIND_IN_SET(ID, '1,2');

MsSQL | SQL Server

SELECT * FROM MENU_MASTER WHERE ID IN (SELECT * FROM STRING_SPLIT ('1,2', ','));
SELECT * FROM MENU_MASTER WHERE CONCAT(',','1,2',',') LIKE CONCAT('%,',ID,',%');

MySQL

SELECT SUBSTRING_INDEX("www.test.com", ".", 1);

MsSQL | SQL Server

select 
CASE
WHEN CHARINDEX('.', 'www.test.com') > 1 THEN
SUBSTRING('www.test.com', 1, CHARINDEX('.','www.test.com')-1)
ELSE 'www.test.com'
END AS SUBSTRING;

MySQL

SELECT PARENT_ID, GROUP_CONCAT(ID SEPARATOR ' / ') AS ids FROM MENU_MASTER GROUP BY PARENT_ID;
SELECT GROUP_CONCAT(MENU_ORDER SEPARATOR ' / ') AS IDS FROM MENU_MASTER;
SELECT GROUP_CONCAT(DISTINCT MENU_ORDER SEPARATOR ' / ') AS IDS FROM MENU_MASTER;

MsSQL | SQL Server

SELECT PARENT_ID, STRING_AGG(ID, ' / ') AS ids FROM MENU_MASTER GROUP BY PARENT_ID;
SELECT STRING_AGG(MENU_ORDER, ' / ') AS IDS FROM MENU_MASTER;
SELECT STRING_AGG(MM.MENU_ORDER, ' / ') AS IDS FROM (SELECT DISTINCT MENU_ORDER FROM MENU_MASTER) MM;

MySQL

1. SELECT MOD(10, 4) AS MODULO;
2. SELECT (10 MOD 4) AS MODULO;
3. SELECT (10 % 4) AS MODULO;

MsSQL | SQL Server

SELECT (10 % 4) AS MODULO;

MySQL

1. SELECT DAYOFWEEK("2019-07-25") AS DAYOFWEEK;
2. SELECT DAYOFWEEK("2019-07-25 11:44:22") AS DAYOFWEEK;
3. SELECT DAYOFWEEK(CURDATE()) AS DAYOFWEEK;

MsSQL | SQL Server

1. SELECT DATEPART(DW, '2019-07-25') AS DATEPART;
2. SELECT DATEPART(WEEKDAY, '2019-07-25') AS DATEPART;
3. SELECT DATEPART(W, '2019-07-25') AS DATEPART;
declare @yr_wk varchar(10) set @yr_wk = '2019-20'
SELECT REPLACE(CONVERT(varchar, DATEADD(week, SUBSTRING(@yr_wk, 6, 2) - 1, CONCAT(SUBSTRING(@yr_wk, 1, 4),'-01-01')) - (DATEPART(weekday, CONCAT(SUBSTRING(@yr_wk, 1, 4),'-01-01')) - 1), 102), '.', '-') AS DATE_FROM_YEAR_WEEK_NUMBER;

MySQL

SELECT IF(500 < 1000, "YES", "NO") AS IF_CONDITION;

MsSQL | SQL Server

SELECT CASE WHEN (500 < 1000) THEN 'YES' ELSE 'NO' END AS IF_CONDITION;

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to setup an AWS EC2 instance

Kafka (AWS MSK) with Golang

Keeping it green.

The subtleties of the Singleton implementation in Golang

Project Management Tools for Boosting Efficiency

Strategic Cooperation Reached Between Memo Labs and Metis, an Ethereum Layer-2 Protocol, on…

My first Medium story

March Release of Saleor: Dark Mode, Model Translations and… Saleor Cloud!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Introduction to REST API

REST API

Rest Services | Rest-API

SQL vs NoSQL, Which is better?

Pagination — Offset vs Cursor in MySQL