Cheat Sheet for mySQL vs t-SQL

Some memory aids for me so that I don't have to keep looking them up:

String ReplaceREPLACE(haystack,needle,replacement)REPLACE(haystack,needle,replacement)
String PositionINSTR(haystack, needle)
LOCATE(needle, haystack [, offset])
PATINDEX(%needle%, haystack)
CHARINDEX(needle, haystack [, offset])
String ConcatenationCONCAT(string1,string2[,stringN])string1 + string2
SS v2012+:
CONCAT(string1, string2 [, stringN ])
String SubstringSUBSTRING( string,start,length )SUBSTRING( string,start,length )
String LengthLENGTH(string)
Dates / Times
Weekday NameDAYNAME(now())DATENAME(dd, getdate())
Weekday NumberDAYOFWEEK(now())DATEPART(dw, getdate())
Month NameMONTHNAME(now())DATENAME(mm, getdate())
Month NumberMONTH(now())DATEPART(mm, getdate())
European Date (dd/mm/yyyy)DATE_FORMAT(now(), '%d/%m/%Y')CONVERT(varchar, getdate(), 103)
Time to SecondsTIME_TO_SEC(now())(DATEPART(hour, getdate()) * 3600) +
(DATEPART(minute, getdate()) * 60) +
(DATEPART(second, getdate()))
Seconds to TimeSEC_TO_TIME( seconds )CONVERT(varchar, DATEADD(ms, seconds * 1000, 0), 114)
Add/Subtract DateDATE_ADD(date,INTERVAL number datepart)
DATE_SUB(date,INTERVAL number datepart)
DATEADD(datepart, number, date)
DATESUB(datepart, number, date)
If-then-elseIF( expression,value_if_true,value_if_false )IIF( expression,value_if_true,value_if_false )
If NullIFNULL(column_name,value_if_null)ISNULL(column_name,value_if_null)
Rank/Rownum (@rownum:=@rownum+1) AS Rownum
LIMIT from_index, number_of_rows
ROW_NUMBER() OVER(ORDER BY column_name ASC) AS Rownum


Credit where Credit is Due:

Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman

Related Articles

Joes Revolver Map


Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Donate to Joel Lipman via PayPal

Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2023 Joel Lipman .com. All Rights Reserved.