<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Functions - MSSQL Query</title>
	<atom:link href="https://mssqlquery.com/category/functions/feed" rel="self" type="application/rss+xml" />
	<link>https://mssqlquery.com</link>
	<description>MSSQL and TSQL Programming and TSQL Examples</description>
	<lastBuildDate>Mon, 17 Jul 2023 20:17:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.1</generator>

<image>
	<url>https://mssqlquery.com/wp-content/uploads/2023/06/cropped-mssql-query-icon-32x32.png</url>
	<title>Functions - MSSQL Query</title>
	<link>https://mssqlquery.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Function to Print Words Side by Side in SQL Server</title>
		<link>https://mssqlquery.com/function-to-print-words-side-by-side-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Wed, 07 Jun 2023 22:06:27 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Function to Print Words Side by Side]]></category>
		<category><![CDATA[print sql server]]></category>
		<category><![CDATA[sql print word]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1606</guid>

					<description><![CDATA[<p>Hello everyone. In this article, I will try to give information about the function that prints the initials of words side by side in SQL Server. In SQL Server, in some cases, you may want to print the initials of the words of a given sentence side by side. You&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-to-print-words-side-by-side-in-sql-server">Function to Print Words Side by Side in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone. In this article, I will try to give information about the function that prints the initials of words side by side in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to print the initials of the words of a given sentence side by side.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION [dbo].[fn_Cumle_Bas_Harfi_Alma] ( @cumle NVARCHAR(4000) )
RETURNS NVARCHAR(2000)
AS
BEGIN
    DECLARE @donensonuc NVARCHAR(2000);

    SET @cumle=RTRIM(LTRIM(@cumle));
    SET @donensonuc=LEFT(@cumle,1);

    WHILE CHARINDEX(' ',@cumle,1)&gt;0 BEGIN
        SET @cumle=LTRIM(RIGHT(@cumle,LEN(@cumle)-CHARINDEX(' ',@cumle,1)));
        SET @donensonuc+=LEFT(@cumle,1);
    END

    RETURN @donensonuc;
END
GO


--Using the Function

SELECT dbo.fn_Cumle_Bas_Harfi_Alma('Yavuz Selim Kart') AS SadeceBasHarfler</code></pre>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" fetchpriority="high" class="alignnone wp-image-1608 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/06/function-to-print-words-side-by-side-in-sql-server-1.jpg" alt="Function to Print Words Side by Side in SQL Server" width="700" height="375" srcset="https://mssqlquery.com/wp-content/uploads/2023/06/function-to-print-words-side-by-side-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2023/06/function-to-print-words-side-by-side-in-sql-server-1-300x161.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have written the initials of the word.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 26</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-to-print-words-side-by-side-in-sql-server">Function to Print Words Side by Side in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Parse URL in SQL Server</title>
		<link>https://mssqlquery.com/parse-url-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Wed, 05 Apr 2023 21:24:41 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Parse URL in SQL Server]]></category>
		<category><![CDATA[SQL Parse]]></category>
		<category><![CDATA[SQL Server Parse]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1490</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will give information about URL parsing in SQL Server. In SQL Server you may want to parse the URL in some cases. Let me explain what I mean. Have a URL address like the one below. https://www.example.com/?utm_source=google&#38;utm_medium=blabla&#38;utm_campaign=gameuser&#38;utm_term=winwin&#38;utm_content=takego We will parse this URL address as&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/parse-url-in-sql-server">Parse URL in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will give information about URL parsing in SQL Server.</p>
<p>In SQL Server you may want to parse the URL in some cases.</p>
<p>Let me explain what I mean. Have a URL address like the one below.</p>
<pre class="line-numbers"><code class="language-sql">https://www.example.com/?utm_source=google&amp;utm_medium=blabla&amp;utm_campaign=gameuser&amp;utm_term=winwin&amp;utm_content=takego</code></pre>
<p>We will parse this URL address as follows.</p>
<p><img decoding="async" class="alignnone wp-image-1495 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/04/parse-url-in-sql-server-1.jpg" alt="Parse URL in SQL Server" width="700" height="71" srcset="https://mssqlquery.com/wp-content/uploads/2023/04/parse-url-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2023/04/parse-url-in-sql-server-1-300x30.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION dbo.ParseQueryString (@url NVARCHAR(MAX))
RETURNS @Result TABLE (
	[Name] NVARCHAR(255)
   ,[Value] NVARCHAR(255)
)
AS
BEGIN
	DECLARE @questionIndex INT = charindex('?', @url)
	DECLARE @queryString NVARCHAR(MAX) = NULL
	DECLARE @startPosition INT = 1
	DECLARE @endPosition INT = 1
	DECLARE @name NVARCHAR(255) = NULL
	DECLARE @value NVARCHAR(255) = NULL

	IF @questionIndex &gt; 0
	BEGIN
		SET @queryString = substring(@url, @questionIndex + 1, LEN(@url))
		SET @startPosition = 1
		SET @endPosition = charindex('&amp;', @queryString)

		WHILE @endPosition &gt; 0
		BEGIN
		SET @name = substring(@queryString, @startPosition, charindex('=', @queryString, @startPosition) - @startPosition)
		SET @value = substring(@queryString, charindex('=', @queryString, @startPosition) + 1, @endPosition - charindex('=', @queryString, @startPosition) - 1)
		INSERT INTO @Result ([Name], [Value])
			VALUES (@name, @value)

		SET @startPosition = @endPosition + 1
		SET @endPosition = charindex('&amp;', @queryString, @startPosition)
		END

		SET @name = substring(@queryString, @startPosition, charindex('=', @queryString, @startPosition) - @startPosition)
		SET @value = substring(@queryString, charindex('=', @queryString, @startPosition) + 1, LEN(@queryString) - charindex('=', @queryString, @startPosition))
		INSERT INTO @Result ([Name], [Value])
			VALUES (@name, @value)
	END

	RETURN
END

--Kullanımı

SELECT
	*
FROM dbo.ParseQueryString('https://www.example.com/?utm_source=google&amp;utm_medium=blabla&amp;utm_campaign=gameuser&amp;utm_term=winwin&amp;utm_content=takego')</code></pre>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" class="alignnone wp-image-1496 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/04/parse-url-in-sql-server-2.jpg" alt="Parse URL in SQL Server" width="700" height="393" srcset="https://mssqlquery.com/wp-content/uploads/2023/04/parse-url-in-sql-server-2.jpg 700w, https://mssqlquery.com/wp-content/uploads/2023/04/parse-url-in-sql-server-2-300x168.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have parsed the URL.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 35</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/parse-url-in-sql-server">Parse URL in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>What are the Differences Between COUNT and COUNT_BIG Functions in SQL Server?</title>
		<link>https://mssqlquery.com/what-are-the-differences-between-count-and-count_big-functions-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Fri, 31 Mar 2023 20:09:43 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[COUNT and COUNT_BIG Functions]]></category>
		<category><![CDATA[SQL Server COUNT]]></category>
		<category><![CDATA[SQL Server COUNT_BIG]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1471</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the differences between the COUNT and COUNT_BIG functions in SQL Server. COUNT and COUNT_BIG are both aggregate functions in SQL Server that are used to count the number of rows in a table or a result set. The&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/what-are-the-differences-between-count-and-count_big-functions-in-sql-server">What are the Differences Between COUNT and COUNT_BIG Functions in SQL Server?</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the differences between the COUNT and COUNT_BIG functions in SQL Server.</p>
<p>COUNT and COUNT_BIG are both aggregate functions in SQL Server that are used to count the number of rows in a table or a result set. The main difference between the two is the data type that they return.</p>
<p>COUNT returns an integer value that represents the number of rows in a table or a result set. If the result set contains no rows, COUNT returns 0.</p>
<p>On the other hand, COUNT_BIG returns a bigint value that represents the number of rows in a table or a result set. If the result set contains no rows, COUNT_BIG returns 0.</p>
<p>The difference between these two functions is important when you are working with very large result sets or tables that contain a large number of rows. If the result set or table contains more than 2^31-1 rows, which is the maximum value that an integer can hold, then COUNT will return an error, whereas COUNT_BIG can handle these large numbers and return the correct count.</p>
<p>In summary, the main difference between COUNT and COUNT_BIG is the data type that they return. COUNT returns an integer value and can handle result sets with less than 2^31-1 rows, whereas COUNT_BIG returns a bigint value and can handle result sets with more than 2^31-1 rows.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 60</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/what-are-the-differences-between-count-and-count_big-functions-in-sql-server">What are the Differences Between COUNT and COUNT_BIG Functions in SQL Server?</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function that Performs Credit Card Verification in SQL Server</title>
		<link>https://mssqlquery.com/function-that-performs-credit-card-verification-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Wed, 22 Mar 2023 21:15:46 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Credit Card Verification]]></category>
		<category><![CDATA[SQL Server Credit Card Verification]]></category>
		<category><![CDATA[TSQL Credit Card Verification]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1457</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the function that performs credit card verification in SQL Server. In some cases, you may want to perform credit card authentication in SQL Server. You can easily do this using the function below. When you create and run&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-that-performs-credit-card-verification-in-sql-server">Function that Performs Credit Card Verification in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the function that performs credit card verification in SQL Server.</p>
<p>In some cases, you may want to perform credit card authentication in SQL Server.</p>
<p>You can easily do this using the function below.</p>
<p><strong></strong></p>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1459 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/03/function-that-performs-credit-card-verification-in-sql-server-1.jpg" alt="Function that Performs Credit Card Verification in SQL Server" width="700" height="467" srcset="https://mssqlquery.com/wp-content/uploads/2023/03/function-that-performs-credit-card-verification-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2023/03/function-that-performs-credit-card-verification-in-sql-server-1-300x200.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have verified the credit card number.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 45</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-that-performs-credit-card-verification-in-sql-server">Function that Performs Credit Card Verification in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function to Split Text Containing Comma Separated Words in SQL Server</title>
		<link>https://mssqlquery.com/function-to-split-text-containing-comma-separated-words-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sat, 18 Mar 2023 18:43:51 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Separated Words SQL]]></category>
		<category><![CDATA[SQL Server Split]]></category>
		<category><![CDATA[TSQL Split]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1443</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the function that splits text containing comma-separated words in SQL Server. In SQL Server you may want to break up comma separated words in some cases. You can easily do this by creating and using the function below.&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-to-split-text-containing-comma-separated-words-in-sql-server">Function to Split Text Containing Comma Separated Words in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the function that splits text containing comma-separated words in SQL Server.</p>
<p>In SQL Server you may want to break up comma separated words in some cases.</p>
<p>You can easily do this by creating and using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION VirgulleAyrilmisMetinleriParcalama (@String VARCHAR(50), @Karakter CHAR(1))
RETURNS @Tablo TABLE (
	Kolon VARCHAR(50)
)
AS
BEGIN
	SET @String = @String + @Karakter
	WHILE (CHARINDEX(@Karakter, @String)) &gt; 0
	BEGIN
	DECLARE @baslangic INT = 1
	DECLARE @son INT
	SET @son = CHARINDEX(@Karakter, @String)
	INSERT INTO @Tablo
		SELECT
			SUBSTRING(@String, @baslangic, @son - 1)
	SET @String = SUBSTRING(@String, @son + 1, LEN(@String))
	END
	RETURN
END

--Using the Function

SELECT
	*
FROM dbo.VirgulleAyrilmisMetinleriParcalama('yavuz, selim, kart', ',')</code></pre>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1445 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/03/function-to-split-text-containing-comma-separated-words-in-sql-server-1.jpg" alt="Function to Split Text Containing Comma Separated Words in SQL Server" width="700" height="381" srcset="https://mssqlquery.com/wp-content/uploads/2023/03/function-to-split-text-containing-comma-separated-words-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2023/03/function-to-split-text-containing-comma-separated-words-in-sql-server-1-300x163.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have broken down the words separated by commas.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 55</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-to-split-text-containing-comma-separated-words-in-sql-server">Function to Split Text Containing Comma Separated Words in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function to Make Email Address Compatible in SQL Server</title>
		<link>https://mssqlquery.com/function-to-make-email-address-compatible-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Wed, 08 Mar 2023 20:48:22 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Compatible Email function]]></category>
		<category><![CDATA[SQL Server Email]]></category>
		<category><![CDATA[TSQL Email]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1383</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the function that makes the e-mail address compatible in SQL Server. In SQL Server, in some cases, Turkish characters may be entered in the e-mail addresses or it may be necessary to correct the e-mail addresses before entering&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-to-make-email-address-compatible-in-sql-server">Function to Make Email Address Compatible in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the function that makes the e-mail address compatible in SQL Server.</p>
<p>In SQL Server, in some cases, Turkish characters may be entered in the e-mail addresses or it may be necessary to correct the e-mail addresses before entering the e-mail addresses.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION dbo.EPosta_Adresi_Duzelt (@EMAIL NVARCHAR(200))
RETURNS NVARCHAR(200)
AS
BEGIN
	DECLARE @TempString NVARCHAR(200)
	SET @TempString = @EMAIL
	IF NULLIF(@TempString, '') IS NOT NULL
	BEGIN
		IF @TempString LIKE '%@%'
		BEGIN
			SET @TempString = REPLACE(@TempString, ' ', '')
			SET @TempString = REPLACE(@TempString, 'Ü', 'u')
			SET @TempString = REPLACE(@TempString, 'ü', 'u')
			SET @TempString = REPLACE(@TempString, 'Ğ', 'g')
			SET @TempString = REPLACE(@TempString, 'ğ', 'g')
			SET @TempString = REPLACE(@TempString, 'Ç', 'c')
			SET @TempString = REPLACE(@TempString, 'ç', 'c')
			SET @TempString = REPLACE(@TempString, 'Ş', 's')
			SET @TempString = REPLACE(@TempString, 'ş', 's')
			SET @TempString = REPLACE(@TempString, 'İ', 'i')
			SET @TempString = REPLACE(@TempString, 'I', 'i')
			SET @TempString = REPLACE(@TempString, 'ı', 'i')
			SET @TempString = REPLACE(@TempString, 'Ö', 'o')
			SET @TempString = REPLACE(@TempString, 'ö', 'o')
			SET @TempString = LOWER(@TempString)
		END
		ELSE
		BEGIN
			SET @TempString = 'Geçersiz E-Mail Adresi';
		END
	END
	ELSE
	BEGIN
		SET @TempString = 'Boş E-Mail Adresi';
	END
	RETURN @TempString
END
GO

--Using the Function

SELECT
	dbo.EPosta_Adresi_Duzelt('Sqlservereğitimleri@sqlservereğitimleri.com')</code></pre>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1385 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/03/function-to-make-email-address-compatible-in-sql-server-1.png" alt="" width="700" height="375" srcset="https://mssqlquery.com/wp-content/uploads/2023/03/function-to-make-email-address-compatible-in-sql-server-1.png 700w, https://mssqlquery.com/wp-content/uploads/2023/03/function-to-make-email-address-compatible-in-sql-server-1-300x161.png 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have made the e-mail address compatible.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 145</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-to-make-email-address-compatible-in-sql-server">Function to Make Email Address Compatible in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function to Clear Special Characters in SQL Server</title>
		<link>https://mssqlquery.com/function-to-clear-special-characters-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Mon, 06 Mar 2023 07:48:23 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Clear Special Characters in SQL Server]]></category>
		<category><![CDATA[sql server clear function]]></category>
		<category><![CDATA[sql server clear special Characters]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1366</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the function that clears special characters in SQL Server. In SQL Server you may want to clear special characters in some cases. You can easily do this using the function below. CREATE FUNCTION fn_Ozel_Karakterleri_Temizle (@Temp VARCHAR(2000)) RETURNS VARCHAR(2000)&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-to-clear-special-characters-in-sql-server">Function to Clear Special Characters in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the function that clears special characters in SQL Server.</p>
<p>In SQL Server you may want to clear special characters in some cases.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION fn_Ozel_Karakterleri_Temizle (@Temp VARCHAR(2000))
RETURNS VARCHAR(2000)
AS
BEGIN
	DECLARE @KeepValues AS VARCHAR(50)
	SET @KeepValues = '%[^A-Za-z0-9.?_,!]%'
	WHILE patindex(@KeepValues, @Temp) &gt; 0
	SET @Temp = STUFF(@Temp, patindex(@KeepValues, @Temp), 1, '')
	RETURN @Temp
END

--<span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">Use of</span></span></span> Function

SELECT dbo.fn_Ozel_Karakterleri_Temizle('ssdfsdfsd**----')</code></pre>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">When you create and run the above function, you will see a result similar to the one below.</span></span></span></p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1369 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/03/function-to-clear-special-characters-in-sql-server-1.png" alt="Function to Clear Special Characters in SQL Server" width="700" height="411" srcset="https://mssqlquery.com/wp-content/uploads/2023/03/function-to-clear-special-characters-in-sql-server-1.png 700w, https://mssqlquery.com/wp-content/uploads/2023/03/function-to-clear-special-characters-in-sql-server-1-300x176.png 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">As you can see, we have cleared the special characters.</span></span></span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">Good luck to everyone in business and life.</span></span></span></p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 64</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-to-clear-special-characters-in-sql-server">Function to Clear Special Characters in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Leap Year Checking Function in SQL Server</title>
		<link>https://mssqlquery.com/leap-year-checking-function-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sun, 08 Jan 2023 15:32:10 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Leap Year Checking Function]]></category>
		<category><![CDATA[SQL Server Leap Year Checking]]></category>
		<category><![CDATA[TSQL Leap Year Checking]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1298</guid>

					<description><![CDATA[<p>Hello everybody, In this article, I will try to give information about the leap year control function in SQL Server. In SQL Server, in some cases, you may want to check for leap years. You can easily do this using the function below. CREATE FUNCTION dbo.IsLeapYear ( @year INT )&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/leap-year-checking-function-in-sql-server">Leap Year Checking Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everybody,</p>
<p>In this article, I will try to give information about the leap year control function in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to check for leap years.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION dbo.IsLeapYear
(
    @year INT
)
RETURNS BIT
AS
BEGIN
    DECLARE @d DATETIME,
            @ans BIT;
    SET @d = CONVERT(DATETIME, '31/01/' + CONVERT(VARCHAR(4), @year), 103);
    IF DATEPART(DAY, DATEADD(MONTH, 1, @d)) = 29
        SET @ans = 1;
    ELSE
        SET @ans = 0;
    RETURN @ans;
END;
GO

--Use of function

SELECT dbo.IsLeapYear(2016);</code></pre>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1300 size-full" src="https://mssqlquery.com/wp-content/uploads/2023/01/leap-year-checking-function-in-sql-server-1.jpg" alt="Leap Year Checking Function in SQL Server" width="700" height="396" srcset="https://mssqlquery.com/wp-content/uploads/2023/01/leap-year-checking-function-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2023/01/leap-year-checking-function-in-sql-server-1-300x170.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have seen whether the entered year is a leap year or not.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 57</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/leap-year-checking-function-in-sql-server">Leap Year Checking Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Differences Between Stored Procedures and Functions in SQL Server</title>
		<link>https://mssqlquery.com/differences-between-stored-procedures-and-functions-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sun, 25 Dec 2022 13:16:55 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Stored Procedures]]></category>
		<category><![CDATA[Differences Between Stored Procedures and Functions in SQL Server]]></category>
		<category><![CDATA[Functions in SQL Server]]></category>
		<category><![CDATA[Stored Procedures and Functions in SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1267</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will talk about the difference between stored procedures and functions in SQL Server. Stored procedures are sql statements that are stored by the database and do not need to be recompiled after the first compilation. Functions are sql codes that can return any&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/differences-between-stored-procedures-and-functions-in-sql-server">Differences Between Stored Procedures and Functions in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will talk about the difference between stored procedures and functions in SQL Server.</p>
<p>Stored procedures are sql statements that are stored by the database and do not need to be recompiled after the first compilation.</p>
<p>Functions are sql codes that can return any type of value.</p>
<p>The differences between them are below.</p>
<ol>
<li>Functions always return a value (Number, string expression, table, etc.) Stored procedures may or may not return a value.</li>
<li>Functions have only input parameters, but stored procedures have both input and output parameters.</li>
<li>Functions can be run by stored procedures, but stored procedures cannot be run inside functions.</li>
<li>Functions can only be used with a Select statement. CRUD operations are not performed with functions. You can do all CRUD (Create/Read/Update/Delete) operations with stored procedures.</li>
<li>You cannot use the try-catch construct in functions, but you can use it with stored procedures.</li>
<li>Functions do not support transaction structures, but stored procedures do.</li>
<li>Functions do not support the PRINT statement. PRINT statement can be used in stored procedures.</li>
<li>The result set returned by the function can be used in JOIN operations. Not used with stored procedures.</li>
<li>You can use TABLE variable inside the function. Functions The use of TEMPORARY TABLE is not allowed. TABLE variable and TEMPORARY TABLE can be used in stored procedure.</li>
</ol>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 94</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/differences-between-stored-procedures-and-functions-in-sql-server">Differences Between Stored Procedures and Functions in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function to Display Difference Between Dates in Days, Hours, Minutes and Seconds in SQL Server</title>
		<link>https://mssqlquery.com/function-to-display-difference-between-dates-in-days-hours-minutes-and-seconds-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Fri, 16 Dec 2022 20:48:35 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Minutes and Seconds in SQL Server]]></category>
		<category><![CDATA[SQL Server Time]]></category>
		<category><![CDATA[SQL Server Time Function]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1249</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about the function that displays the difference between dates as days, hours, minutes and seconds in SQL Server. In SQL Server, in some cases, you may want to display the difference between dates in days, hours, minutes, and&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-to-display-difference-between-dates-in-days-hours-minutes-and-seconds-in-sql-server">Function to Display Difference Between Dates in Days, Hours, Minutes and Seconds in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about the function that displays the difference between dates as days, hours, minutes and seconds in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to display the difference between dates in days, hours, minutes, and seconds.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION dbo.ZamanFarkiBulanFonksiyon
(
    @Tarih1 DATETIME,
    @Tarih2 DATETIME
)
RETURNS VARCHAR(MAX)
AS
BEGIN
    DECLARE @cikis VARCHAR(100);
    DECLARE @saniye BIGINT;
    SET @saniye =
    (
        SELECT DATEDIFF(SECOND, @Tarih1, @Tarih2)
    );
    SET @saniye = ISNULL(@saniye, 0);
    SET @cikis = '0d 00:00:00';
    IF (@saniye &lt; 0)
        RETURN @cikis;
    SET @cikis = CONVERT(VARCHAR, FLOOR(@saniye / 86400)) + 'd ';
    SET @saniye = @saniye % 86400;
    SET @cikis = @cikis + RIGHT('0' + CONVERT(VARCHAR, FLOOR(@saniye / 3600)), 2) + ':';
    SET @saniye = @saniye % 3600;
    SET @cikis = @cikis + RIGHT('0' + CONVERT(VARCHAR, FLOOR(@saniye / 60)), 2) + ':';
    SET @cikis = @cikis + RIGHT('0' + CONVERT(VARCHAR, @saniye % 60), 2); ------------- 
    RETURN @cikis;
------------- 
END;


--Çalıştırılması 

SELECT dbo.ZamanFarkiBulanFonksiyon('2017-10-03 00:00:00', '2017-10-12 00:00:00');
SELECT dbo.ZamanFarkiBulanFonksiyon('2017-10-05 07:30:00', '2017-10-05 07:55:00');
SELECT dbo.ZamanFarkiBulanFonksiyon('2017-09-01 01:46:00', '2017-09-01 10:55:00');
SELECT dbo.ZamanFarkiBulanFonksiyon('2017-11-21 08:21:00', '2017-12-06 18:00:00');</code></pre>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1250 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/12/function-to-display-difference-between-dates-in-days-hours-minutes-and-seconds-in-sql-server-1.jpg" alt="Function to Display Difference Between Dates in Days, Hours, Minutes and Seconds in SQL Server" width="700" height="535" srcset="https://mssqlquery.com/wp-content/uploads/2022/12/function-to-display-difference-between-dates-in-days-hours-minutes-and-seconds-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/12/function-to-display-difference-between-dates-in-days-hours-minutes-and-seconds-in-sql-server-1-300x229.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have displayed the difference between dates as days, hours, minutes and seconds.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 67</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-to-display-difference-between-dates-in-days-hours-minutes-and-seconds-in-sql-server">Function to Display Difference Between Dates in Days, Hours, Minutes and Seconds in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Writing a WordWrap Function in SQL Server</title>
		<link>https://mssqlquery.com/writing-a-wordwrap-function-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sat, 05 Nov 2022 17:04:35 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[WordWrap Function in SQL Server]]></category>
		<category><![CDATA[WordWrap Function SQL]]></category>
		<category><![CDATA[WordWrap Function SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1159</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about writing a WordWrap function in SQL Server. In SQL Server you may need a function like WordWrap in some cases. WordWrap cuts a text to a certain length and displays the remainder on a new line. This is&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/writing-a-wordwrap-function-in-sql-server">Writing a WordWrap Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about writing a WordWrap function in SQL Server.</p>
<p>In SQL Server you may need a function like WordWrap in some cases. WordWrap cuts a text to a certain length and displays the remainder on a new line. This is how the process goes.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION [dbo].[WrapText]
(
    @Metin NVARCHAR(MAX),
    @Uzunluk INT
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
    DECLARE @Sonuc AS NVARCHAR(MAX);
    SELECT @Sonuc = CASE
                        WHEN @Sonuc IS NULL THEN
                            SUBSTRING(@Metin, numara.Numara - @Uzunluk + 1, @Uzunluk)
                        ELSE
                            @Sonuc + CHAR(13) + CHAR(10) + SUBSTRING(@Metin, numara.Numara - @Uzunluk + 1, @Uzunluk)
                    END
    FROM
    (
        SELECT Numara = ROW_NUMBER() OVER (ORDER BY name)
        FROM sys.all_objects
    ) numara
    WHERE numara.Numara &lt;= LEN(@Metin) + @Uzunluk - 1
          AND numara.Numara % @Uzunluk = 0;
    RETURN @Sonuc;
END;

--Use of Function

PRINT dbo.WrapText('abcdefghijklmnopqrstuvwxyz',5)</code></pre>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">When you create the above function and run the code, you will see a result similar to the one below.</span></span></span></p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1160 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/11/writing-a-wordwrap-function-in-sql-server-1.jpg" alt="" width="700" height="395" srcset="https://mssqlquery.com/wp-content/uploads/2022/11/writing-a-wordwrap-function-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/11/writing-a-wordwrap-function-in-sql-server-1-300x169.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, the entered text has been cut to a certain length and passed to the bottom line.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 75</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/writing-a-wordwrap-function-in-sql-server">Writing a WordWrap Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function to Check Mail in SQL Server</title>
		<link>https://mssqlquery.com/function-to-check-mail-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Thu, 20 Oct 2022 21:12:41 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Function to Check Mail in SQL Server]]></category>
		<category><![CDATA[SQL Server mAİL cHECK]]></category>
		<category><![CDATA[SQL Server Mail Control]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1110</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the function that checks mail in SQL Server. In some cases, you may want to check the e-mail address you have in SQL Server. You can easily do this using the function below. CREATE FUNCTION fn_eMailKontrol ( @EmailAddr&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-to-check-mail-in-sql-server">Function to Check Mail in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">Hello everyone,</span></span> </span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">In this article, I will try to give information about the function that checks mail in SQL Server.</span></span> </span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">In some cases, you may want to check the e-mail address you have in SQL Server.</span></span> </span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">You can easily do this using the function below.</span></span></span></p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION fn_eMailKontrol
(
    @EmailAddr VARCHAR(360) 
)
RETURNS BIT 

AS
BEGIN
    DECLARE @AlphabetPlus VARCHAR(255),
            @Max INT,
            @Pos INT, 
            @OK BIT;  
 
    IF @EmailAddr IS NULL
       OR @EmailAddr NOT LIKE '[0-9a-zA-Z]%@__%.__%'
       OR @EmailAddr LIKE '%@%@%'
       OR @EmailAddr LIKE '%..%'
       OR @EmailAddr LIKE '%.@'
       OR @EmailAddr LIKE '%@.'
       OR @EmailAddr LIKE '%@%.-%'
       OR @EmailAddr LIKE '%@%-.%'
       OR @EmailAddr LIKE '%@-%'
       OR CHARINDEX(' ', LTRIM(RTRIM(@EmailAddr))) &gt; 0
        RETURN (0);

    DECLARE @AfterLastDot VARCHAR(360);
    DECLARE @AfterArobase VARCHAR(360);
    DECLARE @BeforeArobase VARCHAR(360);
    DECLARE @HasDomainTooLong BIT = 0;

    SET @AfterLastDot = REVERSE(SUBSTRING(REVERSE(@EmailAddr), 0, CHARINDEX('.', REVERSE(@EmailAddr))));
    IF LEN(@AfterLastDot) NOT
       BETWEEN 2 AND 17
        RETURN (0);

    SET @AfterArobase = REVERSE(SUBSTRING(REVERSE(@EmailAddr), 0, CHARINDEX('@', REVERSE(@EmailAddr))));
    IF LEN(@AfterArobase) NOT
       BETWEEN 2 AND 255
        RETURN (0);

    SELECT TOP 1
           @BeforeArobase = value
    FROM STRING_SPLIT(@EmailAddr, '@');
    IF LEN(@AfterArobase) NOT
       BETWEEN 2 AND 255
        RETURN (0);

    SELECT TOP 1
           @HasDomainTooLong = 1
    FROM STRING_SPLIT(@AfterArobase, '.')
    WHERE LEN(value) &gt; 63;
    IF @HasDomainTooLong = 1
        RETURN (0);

    SELECT @AlphabetPlus = 'abcdefghijklmnopqrstuvwxyz01234567890!#$%&amp;‘*+-/=?^_`.{|}~',
           @Max = LEN(@BeforeArobase),
           @Pos = 0,
           @OK = 1;


    WHILE @Pos &lt; @Max AND @OK = 1
    BEGIN
        SET @Pos = @Pos + 1;
        IF @AlphabetPlus NOT LIKE '%' + SUBSTRING(@BeforeArobase, @Pos, 1) + '%'
            SET @OK = 0;
    END;

    IF @OK = 0
        RETURN (0);

    --Control de la partie domaine en detail
    SELECT @AlphabetPlus = 'abcdefghijklmnopqrstuvwxyz01234567890-.',
           @Max = LEN(@AfterArobase),
           @Pos = 0,
           @OK = 1;

    WHILE @Pos &lt; @Max AND @OK = 1
    BEGIN
        SET @Pos = @Pos + 1;
        IF @AlphabetPlus NOT LIKE '%' + SUBSTRING(@AfterArobase, @Pos, 1) + '%'
            SET @OK = 0;
    END;

    IF @OK = 0
        RETURN (0);

    RETURN (1);

END;
GO


--Kullanımı


SELECT dbo.fn_eMailKontrol('y.selimkart@gmail.com')</code></pre>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">When you create and run the above function, you will see a result similar to the one below.</span></span></span></p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1112 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/10/function-to-check-mail-in-sql-server-1.jpg" alt="" width="700" height="459" srcset="https://mssqlquery.com/wp-content/uploads/2022/10/function-to-check-mail-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/10/function-to-check-mail-in-sql-server-1-300x197.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">As can be seen, it has been seen whether the e-mail address is a valid e-mail address.</span></span></span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">Good luck to everyone in business and life.</span></span></span></p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 81</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-to-check-mail-in-sql-server">Function to Check Mail in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Equivalent of Oracle LAST_DAY Function in SQL Server</title>
		<link>https://mssqlquery.com/equivalent-of-oracle-last_day-function-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Tue, 18 Oct 2022 20:06:50 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[LAST_DAY Function in SQL Server]]></category>
		<category><![CDATA[Oracle LAST_DAY Function in SQL Server]]></category>
		<category><![CDATA[SQL Server LAST_DAY Function]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1104</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will give information about the equivalent of the Oracle LAST_DAY() function in SQL Server. In SQL Server, in some cases, we may want to see and use functions that are in other databases. What is the LAST_DAY() function? The LAST_DAY() function returns the date&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/equivalent-of-oracle-last_day-function-in-sql-server">Equivalent of Oracle LAST_DAY Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">Hello everyone,</span></span> </span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">In this article, I will give information about the equivalent of the Oracle LAST_DAY() function in SQL Server.</span></span> </span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">In SQL Server, in some cases, we may want to see and use functions that are in other databases.</span></span> </span></p>
<p><strong><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">What is the LAST_DAY() function?</span></span> </span></strong></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">The LAST_DAY() function returns the date of the last day of the month containing the date.</span></span> <span class="jCAhz ChMk0b"><span class="ryNqvb">The return type is always DATE, regardless of the date&#8217;s data type.</span></span> </span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">You can easily do this with the help of the code below.</span></span></span></p>
<pre class="line-numbers"><code class="language-sql">DECLARE @Tarih DATETIME
SELECT @Tarih = GETDATE()
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, @Tarih) + 1, 0) - 1</code></pre>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">When you run the above code, you will see a result like the one below.</span></span></span></p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1106 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/10/equivalent-of-oracle-last-day-function-in-sql-server-1.jpg" alt="Equivalent of Oracle LAST_DAY Function in SQL Server" width="700" height="434" srcset="https://mssqlquery.com/wp-content/uploads/2022/10/equivalent-of-oracle-last-day-function-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/10/equivalent-of-oracle-last-day-function-in-sql-server-1-300x186.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>&nbsp;</p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">As you can see, we have returned the last day of the month as a date by using the date information.</span></span> </span></p>
<p><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">Good luck to everyone in business and life.</span></span></span></p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 75</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/equivalent-of-oracle-last_day-function-in-sql-server">Equivalent of Oracle LAST_DAY Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function that Converts Integer Data to Date in SQL Server</title>
		<link>https://mssqlquery.com/function-that-converts-integer-data-to-date-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sun, 02 Oct 2022 21:02:52 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Function that Converts Integer Data to Date in SQL Server]]></category>
		<category><![CDATA[Integer Data to Date in SQL Server]]></category>
		<category><![CDATA[SQL Server Convert]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1082</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the function that converts Integer data to date in SQL Server. In SQL Server, in some cases, you may want to convert Integer data to date. You can easily do this using the function below. CREATE FUNCTION INTtoDATE&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-that-converts-integer-data-to-date-in-sql-server">Function that Converts Integer Data to Date in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the function that converts Integer data to date in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to convert Integer data to date.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION INTtoDATE
(
    @LDATE INT
)
RETURNS DATETIME
AS
BEGIN

    DECLARE @DATE DATETIME,
            @DD INT,
            @MM INT,
            @YYYY INT,
            @DATESTR VARCHAR(12);

    SELECT @DD = ((@LDATE % 65536) / 256);

    SELECT @MM = (@LDATE % 65536) % 256;

    SELECT @YYYY = (@LDATE / 65536);

    SELECT @DATESTR = CAST(@DD AS VARCHAR(2)) + '-' + CAST(@MM AS VARCHAR(2)) + '-' + CAST(@YYYY AS VARCHAR(4));

    SELECT @DATE = CONVERT(DATETIME, @DATESTR, 102);

    RETURN (@DATE);

END;
GO

--Using the Function

SELECT dbo.INTtoDATE(190054667);</code></pre>
<p>When you run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1084 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/10/function-that-converts-integer-data-to-date-in-sql-server-1.jpg" alt="Function that Converts Integer Data to Date in SQL Server" width="700" height="460" srcset="https://mssqlquery.com/wp-content/uploads/2022/10/function-that-converts-integer-data-to-date-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/10/function-that-converts-integer-data-to-date-in-sql-server-1-300x197.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, Integer data has been converted to date.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 103</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-that-converts-integer-data-to-date-in-sql-server">Function that Converts Integer Data to Date in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Writing Oracle NEXT_DAY Function in SQL Server</title>
		<link>https://mssqlquery.com/writing-oracle-next_day-function-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Mon, 26 Sep 2022 17:56:11 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Oracle NEXT_DAY]]></category>
		<category><![CDATA[Oracle NEXT_DAY Function]]></category>
		<category><![CDATA[Oracle NEXT_DAY Function in SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1072</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will give information about writing the Oracle NEXT_DAY function in SQL Server. In SQL Server, in some cases, we may want to see and use functions that exist in other databases. What is the NEXT_DAY function? The NEXT_DAY function has 2 parameters. The first&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/writing-oracle-next_day-function-in-sql-server">Writing Oracle NEXT_DAY Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will give information about writing the Oracle NEXT_DAY function in SQL Server.</p>
<p>In SQL Server, in some cases, we may want to see and use functions that exist in other databases.</p>
<p><strong>What is the NEXT_DAY function?</strong></p>
<p>The NEXT_DAY function has 2 parameters. The first parameter is used to keep the date information, and the second parameter is used to keep the day information of the date we want to see first after the date we specify.</p>
<p>You can easily do this with the help of the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION dbo.SQL_Server_Next_Day
(
    @FromDate DATETIME,
    @DayNumber INT
)
RETURNS DATETIME
AS
BEGIN

    DECLARE @CurrentDate AS DATETIME;
    DECLARE @DayOfWeek AS TINYINT;

    SELECT @DayOfWeek = DATEPART(WEEKDAY, @FromDate);
    SELECT @DayNumber = @DayNumber + 1;

    IF (@DayOfWeek &lt; @DayNumber)
    BEGIN
        SELECT @CurrentDate = (@FromDate + (@DayNumber - @DayOfWeek));
    END;
    ELSE
    BEGIN
        SELECT @CurrentDate = (@FromDate + ((@DayNumber + 2) - (@DayOfWeek - @DayNumber)));
    END;

    RETURN @CurrentDate;
END;

GO

--Use of the function

SELECT dbo.SQL_Server_Next_Day(GETDATE(),5)</code></pre>
<p>When you run the function, you will see a result like the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-1075 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/09/writing-oracle-next-day-function-in-sql-server-1.jpg" alt="Writing Oracle NEXT_DAY Function in SQL Server" width="700" height="442" srcset="https://mssqlquery.com/wp-content/uploads/2022/09/writing-oracle-next-day-function-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/09/writing-oracle-next-day-function-in-sql-server-1-300x189.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, after the date we stated, we saw the day we wanted to see for the first time.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 89</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/writing-oracle-next_day-function-in-sql-server">Writing Oracle NEXT_DAY Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function that Encodes Text to Base64 in SQL Server</title>
		<link>https://mssqlquery.com/function-that-encodes-text-to-base64-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Thu, 05 May 2022 13:46:03 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Base64 in SQL Server]]></category>
		<category><![CDATA[Encodes Text to Base64 in SQL Server]]></category>
		<category><![CDATA[SQL Server Base64 Convert]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=950</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about the function that encodes text to Base64 in SQL Server. In SQL Server, in some cases, you may want to encode text to Base64. You can easily do this using the code below. CREATE FUNCTION [dbo].[fnBase64Encode] (&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-that-encodes-text-to-base64-in-sql-server">Function that Encodes Text to Base64 in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about the function that encodes text to Base64 in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to encode text to Base64.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION [dbo].[fnBase64Encode]
(
    @plain_text VARCHAR(6000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
    --local variables
    DECLARE @output VARCHAR(8000),
            @input_length INTEGER,
            @block_start INTEGER,
            @partial_block_start INTEGER, -- position of last 0, 1 or 2 characters
            @partial_block_length INTEGER,
            @block_val INTEGER,
            @map CHAR(64);
    SET @map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
    --initialise variables
    SET @output = '';
    --set length and count
    SET @input_length = LEN(@plain_text + '#') - 1;
    SET @partial_block_length = @input_length % 3;
    SET @partial_block_start = @input_length - @partial_block_length;
    SET @block_start = 1;
    --for each block
    WHILE @block_start &lt; @partial_block_start
    BEGIN
        SET @block_val = CAST(SUBSTRING(@plain_text, @block_start, 3) AS BINARY(3));
        --encode the 3 character block and add to the output
        SET @output
            = @output + SUBSTRING(@map, @block_val / 262144 + 1, 1) + SUBSTRING(@map, (@block_val / 4096 &amp; 63) + 1, 1)
              + SUBSTRING(@map, (@block_val / 64 &amp; 63) + 1, 1) + SUBSTRING(@map, (@block_val &amp; 63) + 1, 1);
        --increment the counter
        SET @block_start = @block_start + 3;
    END;
    IF @partial_block_length &gt; 0
    BEGIN
        SET @block_val
            = CAST(SUBSTRING(@plain_text, @block_start, @partial_block_length)
                   + REPLICATE(CHAR(0), 3 - @partial_block_length) AS BINARY(3));
        SET @output
            = @output + SUBSTRING(@map, @block_val / 262144 + 1, 1) + SUBSTRING(@map, (@block_val / 4096 &amp; 63) + 1, 1)
              + CASE
                    WHEN @partial_block_length &lt; 2 THEN
                        REPLACE(SUBSTRING(@map, (@block_val / 64 &amp; 63) + 1, 1), 'A', '=')
                    ELSE
                        SUBSTRING(@map, (@block_val / 64 &amp; 63) + 1, 1)
                END + CASE
                          WHEN @partial_block_length &lt; 3 THEN
                              REPLACE(SUBSTRING(@map, (@block_val &amp; 63) + 1, 1), 'A', '=')
                          ELSE
                              SUBSTRING(@map, (@block_val &amp; 63) + 1, 1)
                      END;
    END;
    --return the result
    RETURN @output;
END;


---Kullanımı
 
SELECT dbo.fnBase64Encode('Yavuz Selim Kart') AS Base64</code></pre>
<p>When you run the above code, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-953 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/05/function-that-encodes-text-to-base64-in-sql-server-1.jpg" alt="Function that Encodes Text to Base64 in SQL Server" width="700" height="455" srcset="https://mssqlquery.com/wp-content/uploads/2022/05/function-that-encodes-text-to-base64-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/05/function-that-encodes-text-to-base64-in-sql-server-1-300x195.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have encoded the text to Base64.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 198</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-that-encodes-text-to-base64-in-sql-server">Function that Encodes Text to Base64 in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Function to Remove Duplicates from Comma Separated String in SQL Server</title>
		<link>https://mssqlquery.com/function-to-remove-duplicates-from-comma-separated-string-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 21:41:03 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Comma Separated String in SQL Server]]></category>
		<category><![CDATA[Function to Remove Duplicates]]></category>
		<category><![CDATA[Separated String in SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=871</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about the function that removes duplicates from a comma-separated string in SQL Server. In SQL Server you may want to remove duplicates from comma separated string in some cases You can easily do this using the function below.&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-to-remove-duplicates-from-comma-separated-string-in-sql-server">Function to Remove Duplicates from Comma Separated String in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about the function that removes duplicates from a comma-separated string in SQL Server.</p>
<p>In SQL Server you may want to remove duplicates from comma separated string in some cases</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION dbo.DistinctList
(
    @List VARCHAR(MAX),
    @Delim CHAR
)
RETURNS VARCHAR(MAX)
AS
BEGIN
    DECLARE @ParsedList TABLE
    (
        Item VARCHAR(MAX)
    );

    DECLARE @list1 VARCHAR(MAX);
    DECLARE @Pos INT;
    DECLARE @rList VARCHAR(MAX);

    SET @List = LTRIM(RTRIM(@List)) + @Delim;
    SET @Pos = CHARINDEX(@Delim, @List, 1);

    WHILE @Pos &gt; 0
    BEGIN
        SET @list1 = LTRIM(RTRIM(LEFT(@List, @Pos - 1)));
        IF @list1 &lt;&gt; ''
        BEGIN
            INSERT INTO @ParsedList
            VALUES
            (CAST(@list1 AS VARCHAR(MAX)));
        END;
        SET @List = SUBSTRING(@List, @Pos + 1, LEN(@List));
        SET @Pos = CHARINDEX(@Delim, @List, 1);
    END;

    SELECT @rList = COALESCE(@rList + ',', '') + Item
    FROM
    (SELECT DISTINCT Item FROM @ParsedList) AS t;

    RETURN @rList;
END;
GO


--Use of Function 

SELECT dbo.DistinctList('342,34,456,34,3454,456,aa,bb,cc,aa',',') </code></pre>
<p>When you create and run the above Function, you will see the following result.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-874 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/04/function-to-remove-duplicates-from-comma-separated-string-in-sql-server-1.jpg" alt="Function to Remove Duplicates from Comma Separated String in SQL Server" width="700" height="504" srcset="https://mssqlquery.com/wp-content/uploads/2022/04/function-to-remove-duplicates-from-comma-separated-string-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/04/function-to-remove-duplicates-from-comma-separated-string-in-sql-server-1-300x216.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, the repeated list has been reduced to one.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 143</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-to-remove-duplicates-from-comma-separated-string-in-sql-server">Function to Remove Duplicates from Comma Separated String in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>What are the Differences Between Function and Procedure in SQL Server?</title>
		<link>https://mssqlquery.com/what-are-the-differences-between-function-and-procedure-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Fri, 11 Mar 2022 20:12:36 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Stored Procedures]]></category>
		<category><![CDATA[Differences Between Function and Procedure]]></category>
		<category><![CDATA[Function and Procedure]]></category>
		<category><![CDATA[Function and Procedure in SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=777</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will give information about what are the Differences Between Function and Procedure in SQL Server. This question especially comes to mind of curious friends who are just learning SQL Server. This question may come up in job interviews. It is useful to know briefly,&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/what-are-the-differences-between-function-and-procedure-in-sql-server">What are the Differences Between Function and Procedure in SQL Server?</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will give information about what are the Differences Between Function and Procedure in SQL Server.</p>
<p>This question especially comes to mind of curious friends who are just learning SQL Server. This question may come up in job interviews. It is useful to know briefly, because in the programming world, it is more important to do something efficiently and with less resources than to do it.</p>
<ol>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="2">The function must always return a value.</span> <span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="1" data-number-of-phrases="2">(Number, text, table etc.) but Stored Procedure is optional, it may not have a return value.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="2">You cannot use a try-catch construct in a function.</span> <span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="1" data-number-of-phrases="2">You can use it in Stored Procedure.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">Function can only be used with Select, it doesn&#8217;t update or delete, Stored Procedure can do all CRUD(CREATE/READ/UPDATE/DELETE) operations.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">Function has only input parameters, but Stored Procedures can use both input and output parameters.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">Function can be called by Stored Procedure but Stored Procedure cannot be called by Function.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">Functions do not support Transaction constructs, but Stored Procedures do.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="2">Only variable table values can be used in functions, Temporary tables cannot be used.</span> <span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="1" data-number-of-phrases="2">You can use both in procedures.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">Functions can be used anywhere in the WHERE/HAVING/SELECT section, while Stored Procedures cannot.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">Functions can be called and used using Select and Stored Procedures using Exec or Execute.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">We cannot use indexes in functions, they can be used in Stored Procedures.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">Trigger is not used in Functions, it can be used in Stored Procedure.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">While functions are not compiled once, Stored Procedures are compiled once and work efficiently.</span></span></li>
<li><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="1">It can be used in functions with Join structure, not in Stored Procedures.</span></span></li>
</ol>
<p><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="0" data-number-of-phrases="3">I hope it was useful.</span> </span></p>
<p><span class="VIiyi" lang="en"><span class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="tr" data-phrase-index="2" data-number-of-phrases="3">Good luck to everyone in business and life.</span></span></p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 150</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/what-are-the-differences-between-function-and-procedure-in-sql-server">What are the Differences Between Function and Procedure in SQL Server?</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Difference Between Count and Count_Big Functions in SQL Server</title>
		<link>https://mssqlquery.com/difference-between-count-and-count_big-functions-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sat, 05 Mar 2022 14:20:52 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Count and Count_Big Function]]></category>
		<category><![CDATA[Count and Count_Big Functions in SQL Server]]></category>
		<category><![CDATA[Difference Between Count and Count_Big Functions]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=774</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will give information about the difference between Count and Count_Big functions in SQL Server. There is no difference in functionality between Count and Count_Big. They are almost the same. The only difference is the data type they return and the indexing on the view.&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/difference-between-count-and-count_big-functions-in-sql-server">Difference Between Count and Count_Big Functions in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will give information about the difference between Count and Count_Big functions in SQL Server.</p>
<p>There is no difference in functionality between Count and Count_Big. They are almost the same. The only difference is the data type they return and the indexing on the view.</p>
<p>When you use the COUNT(*) function, it returns the data type as INT (range: -2^31 (-2.147.483.648) to 2^31-1 (2.147.483.647) and storage 4 bytes), while using COUNT_BIG(*) it returns data as BIGINT type (range: -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807) and storage 8 bytes).</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 140</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/difference-between-count-and-count_big-functions-in-sql-server">Difference Between Count and Count_Big Functions in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Simple Interest Calculation Function in SQL Server</title>
		<link>https://mssqlquery.com/simple-interest-calculation-function-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sat, 05 Mar 2022 13:15:49 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Simple Interest Calculation Function in SQL Server]]></category>
		<category><![CDATA[TSQL Interest Calculation]]></category>
		<category><![CDATA[TSQL Simple Interest Calculation]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=768</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about the simple interest calculation function in SQL Server. In SQL Server, in some cases, you may want to calculate interest simply. You can easily do this using the function below. CREATE FUNCTION dbo.SimpleInterestFunction ( @Principal DECIMAL(18, 2) =&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/simple-interest-calculation-function-in-sql-server">Simple Interest Calculation Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about the simple interest calculation function in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to calculate interest simply.</p>
<p>You can easily do this using the function below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION dbo.SimpleInterestFunction
(
    @Principal DECIMAL(18, 2) = 0.0,
    @InterestRate DECIMAL(18, 2) = 0.0,
    @TimeinYears DECIMAL(18, 2) = 0.0
)
RETURNS INT
AS
BEGIN
    RETURN (@Principal * @InterestRate * @TimeinYears / 100);
END;
GO


--Using Function

SELECT dbo.SimpleInterestFunction(1000,10,2)</code></pre>
<p>When you create and run the above function, you will see a result similar to the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-772 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/03/simple-interest-calculation-function-in-sql-server-1.jpg" alt="Simple Interest Calculation Function in SQL Server" width="700" height="430" srcset="https://mssqlquery.com/wp-content/uploads/2022/03/simple-interest-calculation-function-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/03/simple-interest-calculation-function-in-sql-server-1-300x184.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As can be seen, the two-year interest rate of 10 percent has been calculated.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 221</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/simple-interest-calculation-function-in-sql-server">Simple Interest Calculation Function in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
