{"id":81403,"date":"2024-11-25T09:09:31","date_gmt":"2024-11-25T02:09:31","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=81403"},"modified":"2024-11-25T09:09:31","modified_gmt":"2024-11-25T02:09:31","slug":"function-trong-sql","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/function-trong-sql\/","title":{"rendered":"T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/#Function_trong_SQL\" >Function trong SQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/#Quy_tac_can_tuan_thu_khi_tao_va_su_dung_function_trong_SQL\" >Quy t\u1eafc c\u1ea7n tu\u00e2n th\u1ee7 khi t\u1ea1o v\u00e0 s\u1eed d\u1ee5ng function trong SQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/#Function_trong_SQL_do_he_thong_dinh_nghia_san\" >Function trong SQL do h\u1ec7 th\u1ed1ng \u0111\u1ecbnh ngh\u0129a s\u1eb5n<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/#Function_trong_SQL_do_nguoi_dung_dinh_nghia\" >Function trong SQL do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/#Cac_cau_hoi_thuong_gap_ve_Function_trong_SQL\" >C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Function trong SQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/#Tong_ket_function_trong_SQL\" >T\u1ed5ng k\u1ebft function trong SQL<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>SQL cung c\u1ea5p c\u00e1c lo\u1ea1i h\u00e0m (function) gi\u00fap thao t\u00e1c v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u nhanh ch\u00f3ng, t\u1eeb h\u00e0m t\u00edch h\u1ee3p s\u1eb5n \u0111\u1ebfn h\u00e0m do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a (User-Defined Functions &#8211; UDFs). Vi\u1ec7c n\u1eafm v\u1eefng c\u00e1c c\u00e1ch s\u1eed d\u1ee5ng function trong SQL s\u1ebd mang l\u1ea1i l\u1ee3i \u00edch l\u1edbn trong vi\u1ec7c truy xu\u1ea5t th\u00f4ng tin d\u1ec5 d\u00e0ng v\u00e0 ch\u00ednh x\u00e1c h\u01a1n.<\/strong><\/em><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 hi\u1ec3u r\u00f5 h\u01a1n v\u1ec1:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c lo\u1ea1i function trong SQL v\u00e0 c\u00e1ch s\u1eed d\u1ee5ng t\u1eebng lo\u1ea1i function<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Quy t\u1eafc c\u1ea7n tu\u00e2n th\u1ee7 khi t\u1ea1o h\u00e0m<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Function_trong_SQL\"><\/span><b>Function trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Trong SQL, h\u00e0m (function) l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c l\u1ec7nh \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a s\u1eb5n, nh\u1eb1m th\u1ef1c hi\u1ec7n m\u1ed9t c\u00f4ng vi\u1ec7c c\u1ee5 th\u1ec3 v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t k\u1ebft qu\u1ea3. \u0110\u00e2y l\u00e0 c\u00f4ng c\u1ee5 h\u1eefu \u00edch gi\u00fap x\u1eed l\u00fd v\u00e0 thao t\u00e1c d\u1eef li\u1ec7u tr\u1ef1c ti\u1ebfp trong c\u00e2u l\u1ec7nh SQL. C\u00e1c h\u00e0m n\u00e0y c\u00f3 th\u1ec3 nh\u1eadn \u0111\u1ea7u v\u00e0o, th\u1ef1c hi\u1ec7n x\u1eed l\u00fd v\u00e0 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 d\u01b0\u1edbi d\u1ea1ng m\u1ed9t gi\u00e1 tr\u1ecb \u0111\u01a1n ho\u1eb7c m\u1ed9t b\u1ea3ng d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Function trong SQL \u0111\u00f3ng vai tr\u00f2 quan tr\u1ecdng trong vi\u1ec7c t\u1ef1 \u0111\u1ed9ng h\u00f3a c\u00e1c t\u00e1c v\u1ee5 th\u01b0\u1eddng xuy\u00ean, gi\u00fap truy xu\u1ea5t th\u00f4ng tin t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u d\u1ec5 d\u00e0ng v\u00e0 ch\u00ednh x\u00e1c h\u01a1n.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Tuy nhi\u00ean, c\u1ea7n l\u01b0u \u00fd r\u1eb1ng h\u00e0m trong SQL ch\u1ec9 d\u00f9ng \u0111\u1ec3 truy v\u1ea5n v\u00e0 t\u00ednh to\u00e1n, kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c thay \u0111\u1ed5i d\u1eef li\u1ec7u nh\u01b0 INSERT, DELETE, hay UPDATE tr\u1ef1c ti\u1ebfp trong b\u1ea3ng d\u1eef li\u1ec7u.<\/span><\/p>\n<blockquote><p>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/tong-hop-cau-lenh-sql\/\" target=\"_blank\" rel=\"noopener\"><strong>T\u1ed5ng h\u1ee3p 30+ c\u00e2u l\u1ec7nh, to\u00e1n t\u1eed v\u00e0 r\u00e0ng bu\u1ed9c SQL<\/strong><\/a><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Quy_tac_can_tuan_thu_khi_tao_va_su_dung_function_trong_SQL\"><\/span><b>Quy t\u1eafc c\u1ea7n tu\u00e2n th\u1ee7 khi t\u1ea1o v\u00e0 s\u1eed d\u1ee5ng function trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u0110\u1eb7t t\u00ean h\u00e0m h\u1ee3p l\u1ec7<\/b><span style=\"font-weight: 400;\">: T\u00ean h\u00e0m ph\u1ea3i duy nh\u1ea5t trong c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 kh\u00f4ng b\u1eaft \u0111\u1ea7u b\u1eb1ng c\u00e1c k\u00fd t\u1ef1 \u0111\u1eb7c bi\u1ec7t nh\u01b0 @, $, #,&#8230;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ch\u1ec9 h\u1ed7 tr\u1ee3 c\u00e2u l\u1ec7nh SELECT<\/b><span style=\"font-weight: 400;\">: C\u00e1c h\u00e0m ch\u1ec9 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e2u l\u1ec7nh SELECT v\u00e0 kh\u00f4ng h\u1ed7 tr\u1ee3 c\u00e1c thao t\u00e1c nh\u01b0 INSERT, DELETE, ho\u1eb7c UPDATE.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u00ednh linh ho\u1ea1t<\/b><span style=\"font-weight: 400;\">: C\u00f3 th\u1ec3 s\u1eed d\u1ee5ng h\u00e0m \u1edf b\u1ea5t c\u1ee9 \u0111\u00e2u trong truy v\u1ea5n SELECT, v\u00ed d\u1ee5 nh\u01b0 AVG, COUNT, SUM, MIN, DATE, &#8230;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Output<\/b><span style=\"font-weight: 400;\">: H\u00e0m b\u1eaft bu\u1ed9c ph\u1ea3i tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb ho\u1eb7c m\u1ed9t k\u1ebft qu\u1ea3 c\u1ee5 th\u1ec3 sau khi th\u1ef1c thi. Gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1 c\u00f3 th\u1ec3 l\u00e0 m\u1ed9t gi\u00e1 tr\u1ecb \u0111\u01a1n l\u1ebb ho\u1eb7c m\u1ed9t b\u1ea3ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ch\u1ec9 s\u1eed d\u1ee5ng tham s\u1ed1 \u0111\u1ea7u v\u00e0o<\/b><span style=\"font-weight: 400;\">: C\u00e1c h\u00e0m ch\u1ec9 nh\u1eadn tham s\u1ed1 \u0111\u1ea7u v\u00e0o v\u00e0 kh\u00f4ng c\u00f3 tham s\u1ed1 \u0111\u1ea7u ra.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Kh\u00f4ng h\u1ed7 tr\u1ee3 TRY v\u00e0 CATCH<\/b><span style=\"font-weight: 400;\">: Kh\u00f4ng th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c c\u00e2u l\u1ec7nh TRY v\u00e0 CATCH trong h\u00e0m.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Function_trong_SQL_do_he_thong_dinh_nghia_san\"><\/span><b>Function trong SQL do h\u1ec7 th\u1ed1ng \u0111\u1ecbnh ngh\u0129a s\u1eb5n<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">SQL ph\u00e2n lo\u1ea1i c\u00e1c function th\u00e0nh hai lo\u1ea1i ch\u00ednh: <strong>Function trong SQL do h\u1ec7 th\u1ed1ng \u0111\u1ecbnh ngh\u0129a s\u1eb5n<\/strong> (<\/span><span style=\"font-weight: 400;\">System function)<\/span><span style=\"font-weight: 400;\"> v\u00e0 <strong>Function trong SQL do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a<\/strong> (<\/span><span style=\"font-weight: 400;\">User-defined function)<\/span><span style=\"font-weight: 400;\">. M\u1ed7i lo\u1ea1i c\u00f3 vai tr\u00f2 ri\u00eang, cho ph\u00e9p ng\u01b0\u1eddi d\u00f9ng th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c v\u00e0 truy v\u1ea5n d\u1eef li\u1ec7u linh ho\u1ea1t, hi\u1ec7u qu\u1ea3 h\u01a1n trong c\u00e1c h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u (DBMS) kh\u00e1c nhau. Tuy nhi\u00ean, gi\u1eefa c\u00e1c h\u1ec7 qu\u1ea3n tr\u1ecb c\u00f3 s\u1ef1 kh\u00e1c bi\u1ec7t nh\u1ea5t \u0111\u1ecbnh, v\u00ed d\u1ee5 nh\u01b0 MySQL kh\u00f4ng h\u1ed7 tr\u1ee3 table-valued function nh\u01b0 trong SQL Server.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">System function l\u00e0 c\u00e1c h\u00e0m do h\u1ec7 th\u1ed1ng \u0111\u1ecbnh ngh\u0129a s\u1eb5n, hay c\u00f2n g\u1ecdi l\u00e0 c\u00e1c h\u00e0m t\u00edch h\u1ee3p (built-in function). C\u00e1c h\u00e0m n\u00e0y h\u1ed7 tr\u1ee3 ng\u01b0\u1eddi d\u00f9ng th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c ph\u1ed5 bi\u1ebfn tr\u00ean d\u1eef li\u1ec7u m\u00e0 kh\u00f4ng c\u1ea7n t\u1ef1 x\u00e2y d\u1ef1ng t\u1eeb \u0111\u1ea7u. C\u00e1c system function th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e1c c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u00ednh to\u00e1n v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t s\u1ed1 lo\u1ea1i system function th\u00f4ng d\u1ee5ng trong SQL Server bao g\u1ed3m:<\/span><\/p>\n<h3><b>SQL Server String Function<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m chu\u1ed7i (String Functions) trong SQL Server gi\u00fap x\u1eed l\u00fd v\u00e0 thao t\u00e1c tr\u00ean d\u1eef li\u1ec7u d\u1ea1ng chu\u1ed7i nh\u01b0 l\u1ea5y \u0111\u1ed9 d\u00e0i chu\u1ed7i, gh\u00e9p chu\u1ed7i ho\u1eb7c chuy\u1ec3n \u0111\u1ed5i ch\u1eef th\u01b0\u1eddng\/ch\u1eef hoa:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>H\u00e0m<\/b><\/td>\n<td><b>M\u00f4 t\u1ea3<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ASCII<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb ASCII c\u1ee7a k\u00fd t\u1ef1 c\u1ee5 th\u1ec3<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CHAR<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 k\u00fd t\u1ef1 d\u1ef1a tr\u00ean m\u00e3 ASCII<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CHARINDEX<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 v\u1ecb tr\u00ed c\u1ee7a m\u1ed9t chu\u1ed7i con trong chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CONCAT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Gh\u00e9p hai ho\u1eb7c nhi\u1ec1u chu\u1ed7i l\u1ea1i v\u1edbi nhau<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Concat with +<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Gh\u00e9p hai ho\u1eb7c nhi\u1ec1u chu\u1ed7i l\u1ea1i v\u1edbi nhau b\u1eb1ng to\u00e1n t\u1eed &#8216;+&#8217;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CONCAT_WS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Gh\u00e9p hai ho\u1eb7c nhi\u1ec1u chu\u1ed7i l\u1ea1i v\u1edbi nhau v\u1edbi m\u1ed9t k\u00fd t\u1ef1 ph\u00e2n c\u00e1ch (b\u1ecf qua gi\u00e1 tr\u1ecb NULL)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DATALENGTH<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 s\u1ed1 byte \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 bi\u1ec3u di\u1ec5n m\u1ed9t bi\u1ec3u th\u1ee9c<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DIFFERENCE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">So s\u00e1nh hai gi\u00e1 tr\u1ecb SOUNDEX v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t s\u1ed1 nguy\u00ean<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">FORMAT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ecbnh d\u1ea1ng m\u1ed9t gi\u00e1 tr\u1ecb s\u1ed1 ho\u1eb7c ng\u00e0y theo \u0111\u1ecbnh d\u1ea1ng ch\u1ec9 \u0111\u1ecbnh (\u00e1p d\u1ee5ng cho SQL Server 2012 tr\u1edf l\u00ean)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">LEFT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u00edch xu\u1ea5t m\u1ed9t s\u1ed1 k\u00fd t\u1ef1 t\u1eeb chu\u1ed7i (t\u1eeb tr\u00e1i sang)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">LEN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 \u0111\u1ed9 d\u00e0i c\u1ee7a chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">LOWER<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Chuy\u1ec3n chu\u1ed7i th\u00e0nh ch\u1eef th\u01b0\u1eddng<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">LTRIM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lo\u1ea1i b\u1ecf kho\u1ea3ng tr\u1eafng \u1edf \u0111\u1ea7u chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">NCHAR<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 k\u00fd t\u1ef1 Unicode d\u1ef1a tr\u00ean m\u00e3 s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PATINDEX<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 v\u1ecb tr\u00ed c\u1ee7a m\u1ed9t m\u1eabu trong chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">QUOTENAME<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u00eam d\u1ea5u ph\u00e2n c\u00e1ch v\u00e0o chu\u1ed7i \u0111\u1ec3 l\u00e0m cho chu\u1ed7i \u0111\u00f3 tr\u1edf th\u00e0nh m\u1ed9t \u0111\u1ecbnh danh SQL h\u1ee3p l\u1ec7<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">REPLACE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Thay th\u1ebf t\u1ea5t c\u1ea3 c\u00e1c chu\u1ed7i con trong chu\u1ed7i b\u1eb1ng m\u1ed9t chu\u1ed7i con m\u1edbi<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">REPLICATE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1eb7p l\u1ea1i m\u1ed9t chu\u1ed7i s\u1ed1 l\u1ea7n ch\u1ec9 \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">REVERSE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ea3o ng\u01b0\u1ee3c chu\u1ed7i v\u00e0 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">RIGHT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u00edch xu\u1ea5t m\u1ed9t s\u1ed1 k\u00fd t\u1ef1 t\u1eeb chu\u1ed7i (t\u1eeb ph\u1ea3i sang)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">RTRIM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lo\u1ea1i b\u1ecf kho\u1ea3ng tr\u1eafng \u1edf cu\u1ed1i chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SOUNDEX<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t m\u00e3 b\u1ed1n k\u00fd t\u1ef1 \u0111\u1ec3 \u0111\u00e1nh gi\u00e1 s\u1ef1 t\u01b0\u01a1ng \u0111\u1ed3ng c\u1ee7a hai chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SPACE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t chu\u1ed7i ch\u1ee9a m\u1ed9t s\u1ed1 l\u01b0\u1ee3ng k\u00fd t\u1ef1 kho\u1ea3ng tr\u1eafng x\u00e1c \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">STR<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Chuy\u1ec3n \u0111\u1ed5i m\u1ed9t s\u1ed1 th\u00e0nh d\u1ea1ng chu\u1ed7i v\u1edbi \u0111\u1ed9 d\u00e0i chu\u1ed7i v\u00e0 \u0111\u1ed9 ch\u00ednh x\u00e1c th\u1eadp ph\u00e2n \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">STUFF<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X\u00f3a m\u1ed9t ph\u1ea7n c\u1ee7a chu\u1ed7i v\u00e0 ch\u00e8n m\u1ed9t ph\u1ea7n kh\u00e1c v\u00e0o chu\u1ed7i t\u1ea1i v\u1ecb tr\u00ed ch\u1ec9 \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SUBSTRING<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u00edch xu\u1ea5t m\u1ed9t s\u1ed1 k\u00fd t\u1ef1 t\u1eeb chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TRANSLATE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 chu\u1ed7i sau khi c\u00e1c k\u00fd t\u1ef1 \u0111\u01b0\u1ee3c thay th\u1ebf b\u1eb1ng k\u00fd t\u1ef1 kh\u00e1c<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TRIM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lo\u1ea1i b\u1ecf kho\u1ea3ng tr\u1eafng \u1edf \u0111\u1ea7u v\u00e0 cu\u1ed1i chu\u1ed7i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">UNICODE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u00e3 Unicode c\u1ee7a k\u00fd t\u1ef1 \u0111\u1ea7u ti\u00ean trong bi\u1ec3u th\u1ee9c \u0111\u1ea7u v\u00e0o<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">UPPER<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Chuy\u1ec3n chu\u1ed7i th\u00e0nh ch\u1eef hoa<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>SQL Server Math\/Numeric Function<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m s\u1ed1 h\u1ecdc trong SQL Server gi\u00fap th\u1ef1c hi\u1ec7n c\u00e1c ph\u00e9p t\u00ednh to\u00e1n, t\u00ednh gi\u00e1 tr\u1ecb tuy\u1ec7t \u0111\u1ed1i, gi\u00e1 tr\u1ecb trung b\u00ecnh ho\u1eb7c s\u1ed1 ng\u1eabu nhi\u00ean v\u00e0 c\u00e1c ph\u00e9p to\u00e1n to\u00e1n h\u1ecdc kh\u00e1c:\u00a0<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>H\u00e0m<\/b><\/td>\n<td><b>M\u00f4 t\u1ea3<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ABS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb tuy\u1ec7t \u0111\u1ed1i c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ACOS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 arc cosin c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ASIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 arc sin c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ATAN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 arc tangent c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ATN2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 arc tangent c\u1ee7a t\u1ef7 s\u1ed1 gi\u1eefa hai s\u1ed1, t\u01b0\u01a1ng \u1ee9ng v\u1edbi ATAN(y\/x)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">AVG<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb trung b\u00ecnh c\u1ee7a m\u1ed9t bi\u1ec3u th\u1ee9c<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CEILING<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb nguy\u00ean nh\u1ecf nh\u1ea5t l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng s\u1ed1 \u0111\u00e3 cho<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">COUNT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 s\u1ed1 l\u01b0\u1ee3ng c\u00e1c gi\u00e1 tr\u1ecb kh\u00f4ng NULL trong m\u1ed9t c\u1ed9t ho\u1eb7c t\u1ed5ng s\u1ed1 b\u1ea3n ghi khi d\u00f9ng COUNT(*)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">COS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 cosin c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">COT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 cotangent c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DEGREES<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Chuy\u1ec3n gi\u00e1 tr\u1ecb t\u1eeb radian sang \u0111\u1ed9<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">EXP<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 l\u0169y th\u1eeba c\u1ee7a e (s\u1ed1 Euler) v\u1edbi m\u1ed9t s\u1ed1 x\u00e1c \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">FLOOR<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb nguy\u00ean l\u1edbn nh\u1ea5t nh\u1ecf h\u01a1n ho\u1eb7c b\u1eb1ng s\u1ed1 \u0111\u00e3 cho<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">LOG<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 logarit t\u1ef1 nhi\u00ean c\u1ee7a m\u1ed9t s\u1ed1 ho\u1eb7c logarit theo c\u01a1 s\u1ed1 ch\u1ec9 \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">LOG10<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 logarit t\u1ef1 nhi\u00ean c\u1ee7a m\u1ed9t s\u1ed1 c\u01a1 s\u1ed1 10<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">MAX<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb l\u1edbn nh\u1ea5t trong m\u1ed9t t\u1eadp gi\u00e1 tr\u1ecb<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">MIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb nh\u1ecf nh\u1ea5t trong m\u1ed9t t\u1eadp gi\u00e1 tr\u1ecb<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">PI<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb c\u1ee7a PI<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">POWER<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed9t s\u1ed1 l\u0169y th\u1eeba v\u1edbi s\u1ed1 kh\u00e1c<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">RADIANS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Chuy\u1ec3n gi\u00e1 tr\u1ecb t\u1eeb \u0111\u1ed9 sang radian<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">RAND<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t s\u1ed1 ng\u1eabu nhi\u00ean<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ROUND<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0m tr\u00f2n m\u1ed9t s\u1ed1 \u0111\u1ebfn s\u1ed1 ch\u1eef s\u1ed1 th\u1eadp ph\u00e2n ch\u1ec9 \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SIGN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 d\u1ea5u c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SIN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 sin c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SQRT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 c\u0103n b\u1eadc hai c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SQUARE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 b\u00ecnh ph\u01b0\u01a1ng c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SUM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u00ednh t\u1ed5ng c\u00e1c gi\u00e1 tr\u1ecb trong m\u1ed9t t\u1eadp h\u1ee3p<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TAN<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 tangent c\u1ee7a m\u1ed9t s\u1ed1<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>SQL Server Date Function<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m ng\u00e0y th\u00e1ng trong SQL Server gi\u00fap thao t\u00e1c v\u1edbi c\u00e1c d\u1eef li\u1ec7u ng\u00e0y v\u00e0 gi\u1edd nh\u01b0 l\u1ea5y ng\u00e0y hi\u1ec7n t\u1ea1i, t\u00ednh to\u00e1n kho\u1ea3ng th\u1eddi gian ho\u1eb7c tr\u00edch xu\u1ea5t c\u00e1c th\u00e0nh ph\u1ea7n ng\u00e0y th\u00e1ng c\u1ee5 th\u1ec3:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>H\u00e0m<\/b><\/td>\n<td><b>M\u00f4 t\u1ea3<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CURRENT_TIMESTAMP<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ng\u00e0y v\u00e0 gi\u1edd hi\u1ec7n t\u1ea1i, t\u01b0\u01a1ng \u0111\u01b0\u01a1ng v\u1edbi GETDATE nh\u01b0ng kh\u00f4ng nh\u1eadn tham s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DATEADD<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u00eam m\u1ed9t kho\u1ea3ng th\u1eddi gian v\u00e0o m\u1ed9t ng\u00e0y r\u1ed3i tr\u1ea3 v\u1ec1 ng\u00e0y m\u1edbi<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DATEDIFF<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 kho\u1ea3ng c\u00e1ch gi\u1eefa hai ng\u00e0y<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DATEFROMPARTS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t ng\u00e0y t\u1eeb c\u00e1c th\u00e0nh ph\u1ea7n ch\u1ec9 \u0111\u1ecbnh (n\u0103m, th\u00e1ng, ng\u00e0y)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DATENAME<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t ph\u1ea7n c\u1ee5 th\u1ec3 c\u1ee7a ng\u00e0y (d\u01b0\u1edbi d\u1ea1ng chu\u1ed7i)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DATEPART<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t ph\u1ea7n c\u1ee5 th\u1ec3 c\u1ee7a ng\u00e0y (d\u01b0\u1edbi d\u1ea1ng s\u1ed1 nguy\u00ean)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">DAY<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ng\u00e0y trong th\u00e1ng t\u1eeb m\u1ed9t ng\u00e0y c\u1ee5 th\u1ec3<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">GETDATE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ng\u00e0y gi\u1edd hi\u1ec7n t\u1ea1i c\u1ee7a h\u1ec7 th\u1ed1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">GETUTCDATE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ng\u00e0y gi\u1edd UTC hi\u1ec7n t\u1ea1i c\u1ee7a h\u1ec7 th\u1ed1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ISDATE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3m tra m\u1ed9t bi\u1ec3u th\u1ee9c v\u00e0 tr\u1ea3 v\u1ec1 1 n\u1ebfu l\u00e0 ng\u00e0y h\u1ee3p l\u1ec7, ng\u01b0\u1ee3c l\u1ea1i tr\u1ea3 v\u1ec1 0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">MONTH<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ph\u1ea7n th\u00e1ng t\u1eeb m\u1ed9t ng\u00e0y nh\u1ea5t \u0111\u1ecbnh (m\u1ed9t s\u1ed1 t\u1eeb 1 \u0111\u1ebfn 12)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SYSDATETIME<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 ng\u00e0y gi\u1edd hi\u1ec7n t\u1ea1i c\u1ee7a h\u1ec7 th\u1ed1ng SQL Server<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YEAR<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 n\u0103m t\u1eeb m\u1ed9t ng\u00e0y nh\u1ea5t \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>SQL Server Advanced Function<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m n\u00e2ng cao trong SQL Server h\u1ed7 tr\u1ee3 c\u00e1c ph\u00e9p bi\u1ebfn \u0111\u1ed5i, ki\u1ec3m tra ki\u1ec3u d\u1eef li\u1ec7u v\u00e0 \u0111i\u1ec1u ki\u1ec7n logic, gi\u00fap x\u1eed l\u00fd c\u00e1c t\u00ecnh hu\u1ed1ng ph\u1ee9c t\u1ea1p h\u01a1n khi truy v\u1ea5n d\u1eef li\u1ec7u:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>H\u00e0m<\/b><\/td>\n<td><b>M\u00f4 t\u1ea3<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CAST<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Chuy\u1ec3n \u0111\u1ed5i gi\u00e1 tr\u1ecb (c\u1ee7a b\u1ea5t k\u1ef3 lo\u1ea1i n\u00e0o) th\u00e0nh ki\u1ec3u d\u1eef li\u1ec7u ch\u1ec9 \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">COALESCE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb \u0111\u1ea7u ti\u00ean kh\u00f4ng ph\u1ea3i NULL trong m\u1ed9t danh s\u00e1ch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CONVERT<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Chuy\u1ec3n \u0111\u1ed5i gi\u00e1 tr\u1ecb (c\u1ee7a b\u1ea5t k\u1ef3 lo\u1ea1i n\u00e0o) th\u00e0nh ki\u1ec3u d\u1eef li\u1ec7u ch\u1ec9 \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">CURRENT_USER<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 t\u00ean c\u1ee7a ng\u01b0\u1eddi d\u00f9ng hi\u1ec7n t\u1ea1i trong c\u01a1 s\u1edf d\u1eef li\u1ec7u SQL Server<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">IIF<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb n\u1ebfu \u0111i\u1ec1u ki\u1ec7n l\u00e0 TRUE, ho\u1eb7c gi\u00e1 tr\u1ecb kh\u00e1c n\u1ebfu \u0111i\u1ec1u ki\u1ec7n l\u00e0 FALSE<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ISNULL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb ch\u1ec9 \u0111\u1ecbnh n\u1ebfu bi\u1ec3u th\u1ee9c l\u00e0 NULL, n\u1ebfu kh\u00f4ng th\u00ec tr\u1ea3 v\u1ec1 bi\u1ec3u th\u1ee9c<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ISNUMERIC<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3m tra li\u1ec7u m\u1ed9t bi\u1ec3u th\u1ee9c c\u00f3 ph\u1ea3i l\u00e0 s\u1ed1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">NULLIF<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 NULL n\u1ebfu hai bi\u1ec3u th\u1ee9c b\u1eb1ng nhau<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SESSION_USER<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 t\u00ean c\u1ee7a ng\u01b0\u1eddi d\u00f9ng hi\u1ec7n t\u1ea1i trong c\u01a1 s\u1edf d\u1eef li\u1ec7u SQL Server<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SESSIONPROPERTY<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed9t thu\u1ed9c t\u00ednh phi\u00ean ch\u1ec9 \u0111\u1ecbnh, ch\u1eb3ng h\u1ea1n nh\u01b0 LANGUAGE ho\u1eb7c ISOLATION LEVEL<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">SYSTEM_USER<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 t\u00ean \u0111\u0103ng nh\u1eadp c\u1ee7a ng\u01b0\u1eddi d\u00f9ng hi\u1ec7n t\u1ea1i<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">USER_<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 t\u00ean ng\u01b0\u1eddi d\u00f9ng c\u01a1 s\u1edf d\u1eef li\u1ec7u d\u1ef1a tr\u00ean ID ch\u1ec9 \u0111\u1ecbnh<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>M\u1ed9t s\u1ed1 v\u00ed d\u1ee5<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p v\u00e0 c\u00e1ch tri\u1ec3n khai c\u00f3 th\u1ec3 thay \u0111\u1ed5i t\u00f9y theo h\u1ec7 qu\u1ea3n tr\u1ecb. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 v\u00ed d\u1ee5 v\u1ec1 c\u00fa ph\u00e1p trong SQL Server:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u00ednh gi\u00e1 tr\u1ecb trung b\u00ecnh c\u1ee7a m\u1ed9t c\u1ed9t, s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT AVG(So_luong) FROM Ten_bang;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 ki\u1ec3m tra n\u1ebfu m\u1ed9t gi\u00e1 tr\u1ecb l\u00e0 NULL v\u00e0 thay th\u1ebf b\u1eb1ng m\u1ed9t gi\u00e1 tr\u1ecb kh\u00e1c n\u1ebfu \u0111\u00fang, d\u00f9ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT ISNULL(ten_cot, 'Gia_tri_mac_dinh') FROM Ten_bang;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 n\u1ed1i chu\u1ed7i trong SQL Server, ta c\u00f3 th\u1ec3 d\u00f9ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT CONCAT('Hello', ' ', 'World!');<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh tr\u00ean tr\u1ea3 v\u1ec1 chu\u1ed7i <\/span><span style=\"font-weight: 400;\">&#8216;Hello World!&#8217;<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Function_trong_SQL_do_nguoi_dung_dinh_nghia\"><\/span>Function trong SQL do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">User-defined function (UDF) l\u00e0 c\u00e1c h\u00e0m do ng\u01b0\u1eddi d\u00f9ng t\u1ea1o ra, \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u1ee7a h\u1ec7 th\u1ed1ng ho\u1eb7c trong c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a. UDF gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a m\u00e3 truy v\u1ea5n v\u00e0 t\u0103ng t\u00ednh \u0111\u1ecdc hi\u1ec3u c\u1ee7a truy v\u1ea5n SQL. C\u00e1c user-defined function ch\u1ee7 y\u1ebfu c\u00f3 hai lo\u1ea1i:<\/span><\/p>\n<h3><b>Scalar Function<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Scalar Function l\u00e0 lo\u1ea1i h\u00e0m tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb duy nh\u1ea5t, c\u00f3 th\u1ec3 l\u00e0 ki\u1ec3u s\u1ed1, chu\u1ed7i, ng\u00e0y gi\u1edd,&#8230; Ch\u00fang th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c ph\u00e9p t\u00ednh \u0111\u01a1n gi\u1ea3n ho\u1eb7c thao t\u00e1c v\u1edbi c\u00e1c gi\u00e1 tr\u1ecb c\u1ee5 th\u1ec3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE FUNCTION function_name (parameter1 datatype, parameter2 datatype, ...)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RETURNS return_datatype\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">AS<\/span>\r\n\r\n<span style=\"font-weight: 400;\">BEGIN\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-- Ph\u1ea7n th\u00e2n h\u00e0m RETURN (gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1);\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">END;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u1ea1o m\u1ed9t scalar function \u0111\u1ec3 t\u00ednh di\u1ec7n t\u00edch h\u00ecnh tr\u00f2n d\u1ef1a tr\u00ean b\u00e1n k\u00ednh ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE FUNCTION dbo.CircleArea (@radius FLOAT)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RETURNS FLOAT\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">AS\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">BEGIN\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0RETURN PI() * @radius *@radius;\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">END;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 s\u1eed d\u1ee5ng h\u00e0m tr\u00ean ta th\u1ef1c thi c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT dbo.CircleArea(5) AS Area; -- K\u1ebft qu\u1ea3: 78.5398<\/span><\/pre>\n<h3><b>Table-Valued Function<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Table-Valued Function (TVF) tr\u1ea3 v\u1ec1 m\u1ed9t t\u1eadp h\u1ee3p k\u1ebft qu\u1ea3 d\u01b0\u1edbi d\u1ea1ng b\u1ea3ng v\u00e0 cho ph\u00e9p ng\u01b0\u1eddi d\u00f9ng s\u1eed d\u1ee5ng n\u00f3 trong c\u00e1c c\u00e2u truy v\u1ea5n nh\u01b0 JOIN ho\u1eb7c APPLY \u0111\u1ec3 l\u1ea5y d\u1eef li\u1ec7u \u0111\u1ed9ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE FUNCTION function_name (parameter1 datatype, parameter2 datatype, ...)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RETURNS TABLE\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">AS\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RETURN\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">(<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0-- C\u00e2u truy v\u1ea5n tr\u1ea3 v\u1ec1 b\u1ea3ng\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0SELECT column1, column2, ...\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0FROM table_name\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0WHERE condition\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 t\u1ea1o m\u1ed9t table-valued function tr\u1ea3 v\u1ec1 danh s\u00e1ch s\u1ea3n ph\u1ea9m c\u00f3 gi\u00e1 l\u1edbn h\u01a1n m\u1ed9t m\u1ee9c nh\u1ea5t \u0111\u1ecbnh ta c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE FUNCTION dbo.ExpensiveProducts (@min_price DECIMAL)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RETURNS TABLE\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">AS\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RETURN\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">(\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0SELECTProductID, ProductName, Price<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0FROM Products\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0WHERE Price &gt; @min_price\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 s\u1eed d\u1ee5ng h\u00e0m tr\u00ean ta d\u00f9ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT * FROM dbo.ExpensiveProducts(500); -- L\u1ea5y danh s\u00e1ch s\u1ea3n ph\u1ea9m c\u00f3 gi\u00e1 &gt; 500<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_thuong_gap_ve_Function_trong_SQL\"><\/span><b>C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Function trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng table-valued function?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">TVFs n\u00ean \u0111\u01b0\u1ee3c d\u00f9ng khi c\u1ea7n tr\u1ea3 v\u1ec1 m\u1ed9t t\u1eadp d\u1eef li\u1ec7u \u0111\u1ed9ng c\u00f3 tham s\u1ed1 v\u00e0 c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng nh\u01b0 b\u1ea3ng trong truy v\u1ea5n. Ch\u00fang r\u1ea5t h\u1eefu \u00edch cho c\u00e1c view c\u00f3 tham s\u1ed1 v\u00e0 linh ho\u1ea1t h\u01a1n stored procedures v\u00ec c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c d\u00f9ng trong <\/span><span style=\"font-weight: 400;\">JOIN<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">APPLY<\/span><span style=\"font-weight: 400;\"> trong c\u00e1c truy v\u1ea5n ph\u1ee9c t\u1ea1p.<\/span><\/p>\n<h3><b>C\u00f3 th\u1ec3 thay \u0111\u1ed5i d\u1eef li\u1ec7u b\u00ean trong function kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Kh\u00f4ng, function trong SQL th\u01b0\u1eddng ch\u1ec9 d\u00f9ng \u0111\u1ec3 x\u1eed l\u00fd v\u00e0 tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u ch\u1ee9 kh\u00f4ng th\u1ec3 thay \u0111\u1ed5i d\u1eef li\u1ec7u b\u00ean trong c\u01a1 s\u1edf d\u1eef li\u1ec7u (kh\u00f4ng th\u1ec3 d\u00f9ng c\u00e1c c\u00e2u l\u1ec7nh nh\u01b0 <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">UPDATE<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> tr\u1ef1c ti\u1ebfp).<\/span><\/p>\n<h3><b>Function c\u00f3 th\u1ec3 nh\u1eadn tham s\u1ed1 kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3, function c\u00f3 th\u1ec3 nh\u1eadn tham s\u1ed1 \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o, cho ph\u00e9p t\u00f9y ch\u1ec9nh k\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1 d\u1ef1a tr\u00ean c\u00e1c gi\u00e1 tr\u1ecb tham s\u1ed1.<\/span><\/p>\n<h3><b>Function kh\u00e1c g\u00ec v\u1edbi th\u1ee7 t\u1ee5c?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Function ph\u1ea3i tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb (c\u00f3 th\u1ec3 l\u00e0 m\u1ed9t b\u1ea3ng), th\u01b0\u1eddng d\u00f9ng trong c\u00e1c truy v\u1ea5n. Th\u1ee7 t\u1ee5c (Stored Procedure) linh ho\u1ea1t h\u01a1n, c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n nhi\u1ec1u t\u00e1c v\u1ee5 nh\u01b0 thay \u0111\u1ed5i d\u1eef li\u1ec7u, v\u00e0 kh\u00f4ng nh\u1ea5t thi\u1ebft ph\u1ea3i tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 t\u00ecm hi\u1ec3u th\u00eam v\u1ec1 th\u1ee7 t\u1ee5c trong SQL <\/span><span style=\"font-weight: 400;\">t\u1ea1i \u0111\u00e2y<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_function_trong_SQL\"><\/span><b>T\u1ed5ng k\u1ebft function trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Hi\u1ec3u r\u00f5 v\u1ec1 c\u00e1c lo\u1ea1i function trong SQL v\u00e0 c\u00e1ch s\u1eed d\u1ee5ng ch\u00fang gi\u00fap b\u1ea1n linh ho\u1ea1t h\u01a1n khi l\u00e0m vi\u1ec7c v\u1edbi d\u1eef li\u1ec7u. Vi\u1ec7c \u00e1p d\u1ee5ng \u0111\u00fang c\u00e1c lo\u1ea1i h\u00e0m kh\u00f4ng ch\u1ec9 gi\u00fap t\u0103ng t\u1ed1c \u0111\u1ed9 x\u1eed l\u00fd m\u00e0 c\u00f2n gi\u00fap truy v\u1ea5n tr\u1edf n\u00ean \u0111\u01a1n gi\u1ea3n v\u00e0 d\u1ec5 hi\u1ec3u h\u01a1n, n\u00e2ng cao hi\u1ec7u qu\u1ea3 qu\u1ea3n l\u00fd v\u00e0 ph\u00e2n t\u00edch d\u1eef li\u1ec7u trong c\u00e1c h\u1ec7 th\u1ed1ng SQL.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ITviec hy v\u1ecdng b\u00e0i vi\u1ebft tr\u00ean \u0111\u00e3 gi\u00fap b\u1ea1n c\u00f3 c\u00e1i nh\u00ecn chi ti\u1ebft h\u01a1n v\u1ec1 h\u00e0m trong SQL.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL cung c\u1ea5p c\u00e1c lo\u1ea1i h\u00e0m (function) gi\u00fap thao t\u00e1c v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u nhanh ch\u00f3ng, t\u1eeb h\u00e0m t\u00edch h\u1ee3p s\u1eb5n \u0111\u1ebfn h\u00e0m do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a (User-Defined Functions &#8211; UDFs). Vi\u1ec7c n\u1eafm v\u1eefng c\u00e1c c\u00e1ch s\u1eed d\u1ee5ng function trong SQL s\u1ebd mang l\u1ea1i l\u1ee3i \u00edch l\u1edbn trong vi\u1ec7c truy xu\u1ea5t th\u00f4ng tin [&hellip;]<\/p>\n","protected":false},"author":209,"featured_media":81680,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-81403","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft - ITviec Blog<\/title>\n<meta name=\"description\" content=\"T\u1ed5ng quan 90+ function trong SQL, chi ti\u1ebft c\u00e1c h\u00e0m t\u1eeb scalar function, table-valued function \u0111\u1ebfn user-defined function (UDF).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft\" \/>\n<meta property=\"og:description\" content=\"SQL cung c\u1ea5p c\u00e1c lo\u1ea1i h\u00e0m (function) gi\u00fap thao t\u00e1c v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u nhanh ch\u00f3ng, t\u1eeb h\u00e0m t\u00edch h\u1ee3p s\u1eb5n \u0111\u1ebfn h\u00e0m do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a (User-Defined\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/function-trong-sql\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-25T02:09:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/11\/Function-trong-SQL-vippro.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"790\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"M\u1ef9 Duy\u00ean\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"M\u1ef9 Duy\u00ean\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft - ITviec Blog","description":"T\u1ed5ng quan 90+ function trong SQL, chi ti\u1ebft c\u00e1c h\u00e0m t\u1eeb scalar function, table-valued function \u0111\u1ebfn user-defined function (UDF).","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/function-trong-sql\/","og_locale":"vi_VN","og_type":"article","og_title":"T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft","og_description":"SQL cung c\u1ea5p c\u00e1c lo\u1ea1i h\u00e0m (function) gi\u00fap thao t\u00e1c v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u nhanh ch\u00f3ng, t\u1eeb h\u00e0m t\u00edch h\u1ee3p s\u1eb5n \u0111\u1ebfn h\u00e0m do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a (User-Defined","og_url":"https:\/\/itviec.com\/blog\/function-trong-sql\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2024-11-25T02:09:31+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/11\/Function-trong-SQL-vippro.jpg","type":"image\/jpeg"}],"author":"M\u1ef9 Duy\u00ean","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"M\u1ef9 Duy\u00ean","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"14 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/"},"author":{"name":"M\u1ef9 Duy\u00ean","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7"},"headline":"T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft","datePublished":"2024-11-25T02:09:31+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/"},"wordCount":3475,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/11\/Function-trong-SQL-vippro.jpg","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/","url":"https:\/\/itviec.com\/blog\/function-trong-sql\/","name":"T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/11\/Function-trong-SQL-vippro.jpg","datePublished":"2024-11-25T02:09:31+00:00","description":"T\u1ed5ng quan 90+ function trong SQL, chi ti\u1ebft c\u00e1c h\u00e0m t\u1eeb scalar function, table-valued function \u0111\u1ebfn user-defined function (UDF).","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/function-trong-sql\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/11\/Function-trong-SQL-vippro.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/11\/Function-trong-SQL-vippro.jpg","width":1500,"height":790,"caption":"Function trong SQL - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/function-trong-sql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7","name":"M\u1ef9 Duy\u00ean","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","caption":"M\u1ef9 Duy\u00ean"},"url":"https:\/\/itviec.com\/blog\/author\/my-duyen\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/81403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/209"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=81403"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/81403\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/81680"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=81403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=81403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=81403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}