<?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>string &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/string/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Fri, 10 Nov 2017 18:37:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>PostgreSQL: Replace String data in all the Columns of a Table</title>
		<link>https://www.dbrnd.com/2017/12/postgresql-replace-string-data-in-all-the-columns-of-a-table/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 04 Dec 2017 16:16:06 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6734</guid>

					<description><![CDATA[In this post, I am sharing a custom function which will replace the String in all the column of a PostgreSQL Table. Postgres provides the string replace function, but at a time you can replace string for a particular column. Recently, I got the requirement like replace same string value in multiple columns. So, I [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-replace-string-data-in-all-the-columns-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Replace%20String%20data%20in%20all%20the%20Columns%20of%20a%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-replace-string-data-in-all-the-columns-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Replace%20String%20data%20in%20all%20the%20Columns%20of%20a%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-replace-string-data-in-all-the-columns-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Replace%20String%20data%20in%20all%20the%20Columns%20of%20a%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-replace-string-data-in-all-the-columns-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Replace%20String%20data%20in%20all%20the%20Columns%20of%20a%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-replace-string-data-in-all-the-columns-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Replace%20String%20data%20in%20all%20the%20Columns%20of%20a%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-replace-string-data-in-all-the-columns-of-a-table%2F&amp;linkname=PostgreSQL%3A%20Replace%20String%20data%20in%20all%20the%20Columns%20of%20a%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F12%2Fpostgresql-replace-string-data-in-all-the-columns-of-a-table%2F&#038;title=PostgreSQL%3A%20Replace%20String%20data%20in%20all%20the%20Columns%20of%20a%20Table" data-a2a-url="https://www.dbrnd.com/2017/12/postgresql-replace-string-data-in-all-the-columns-of-a-table/" data-a2a-title="PostgreSQL: Replace String data in all the Columns of a Table"></a></p><p>In this post, I am sharing a custom function which will replace the String in all the column of a PostgreSQL Table. </p>
<p>Postgres provides the string replace function, but at a time you can replace string for a particular column. </p>
<p>Recently, I got the requirement like replace same string value in multiple columns.<br />
So, I prepared a user-defined function which I am sharing here. </p>
<p>Please check code, and try it yourself:</p>
<p><strong>Create a sample table with data:</strong></p>
<pre class="crayon-plain-tag">create table tbl_str (t1 character varying,t2 character varying);

insert into tbl_str values 
('AA','BB'),('BB','DD')
,('CC','BB'),('FF','GG');</pre> </p>
<p><strong>Create a function for replacing string in all columns:</strong></p>
<pre class="crayon-plain-tag">create or replace function fn_replace_string_for_all_columns(tablename text,oldvalue text,newvalue text) 
returns void as 
$$
declare 
eachrw record;
begin
    for eachrw in 
        select 'UPDATE '||$1||' SET '||C.COLUMN_NAME||' = REPLACE ('||C.COLUMN_NAME||','''||$2||''','''||$3||'''); ' SQLQuery
        FROM (select column_name from information_schema.columns where table_schema='public' and table_name =$1)c
    loop
        EXECUTE eachrw.SQLQuery;
    end loop;
end;
$$language plpgsql;</pre> </p>
<p><strong>Call the function:</strong></p>
<pre class="crayon-plain-tag">select *from fn_replace_string_for_all_columns('tbl_str', 'BB', 'ZZ');</pre> </p>
<p><strong>Check the result: &#8216;BB&#8217; replaced by &#8216;ZZ&#8217;</strong></p>
<pre class="crayon-plain-tag">select *from tbl_str

  t1 | t2 
-----------
  AA | ZZ
  ZZ | DD
  CC | ZZ
  FF | GG</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Puzzle: SQL Advance Query &#8211; Find the count of Lowercase, Uppercase, Special Characters</title>
		<link>https://www.dbrnd.com/2017/11/sql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters/</link>
					<comments>https://www.dbrnd.com/2017/11/sql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 21 Nov 2017 16:16:07 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Lowercase]]></category>
		<category><![CDATA[SQL Advance Query]]></category>
		<category><![CDATA[SQL Interview]]></category>
		<category><![CDATA[SQL Problem]]></category>
		<category><![CDATA[SQL Programming]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[Uppercase]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6557</guid>

					<description><![CDATA[Check the below input string and expected output for counting the total Lowercase, Uppercase and Other Characters (Including SPACE) in the given string. Input String: [crayon-6ab3eb5a4b883142339877/] Expected Output: [crayon-6ab3eb5a4b884062291925/] Solution: [crayon-6ab3eb5a4b885037082445/] Please try the different solution for this puzzle and share it via comment...]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Find%20the%20count%20of%20Lowercase%2C%20Uppercase%2C%20Special%20Characters" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Find%20the%20count%20of%20Lowercase%2C%20Uppercase%2C%20Special%20Characters" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Find%20the%20count%20of%20Lowercase%2C%20Uppercase%2C%20Special%20Characters" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Find%20the%20count%20of%20Lowercase%2C%20Uppercase%2C%20Special%20Characters" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Find%20the%20count%20of%20Lowercase%2C%20Uppercase%2C%20Special%20Characters" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Find%20the%20count%20of%20Lowercase%2C%20Uppercase%2C%20Special%20Characters" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters%2F&#038;title=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Find%20the%20count%20of%20Lowercase%2C%20Uppercase%2C%20Special%20Characters" data-a2a-url="https://www.dbrnd.com/2017/11/sql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters/" data-a2a-title="SQL Puzzle: SQL Advance Query – Find the count of Lowercase, Uppercase, Special Characters"></a></p><p>Check the below input string and expected output for counting the total Lowercase, Uppercase and Other Characters (Including SPACE) in the given string.</p>
<p><strong>Input String:</strong></p>
<pre class="crayon-plain-tag">'I am Anvesh Patel, owner @str DBRND.COM'</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">UpperCase_Count LowerCase_Count OtherCharacter_Count
--------------- --------------- --------------------
11              19              9</pre> </p>
<p><strong>Solution:</strong></p>
<pre class="crayon-plain-tag">DECLARE @str AS VARCHAR(100) = 'I am Anvesh Patel, owner @str DBRND.COM'
 
SELECT 
        SUM(CASE WHEN ASCII(string) BETWEEN 65 AND 90 THEN 1 ELSE 0 END) as UpperCase_Count
       ,SUM(CASE WHEN ASCII(string) BETWEEN 97 AND 122 THEN 1 ELSE 0 END) as LowerCase_Count
       ,SUM(CASE WHEN (( ASCII(string) NOT BETWEEN 97 AND 122 ) AND ( ASCII(string) NOT BETWEEN 65 AND 90 )) THEN 1 ELSE 0 END) as OtherCharacter_Count 
FROM
(
    SELECT 
		DISTINCT Number 
		,SUBSTRING(@str,Number,1) as string
    FROM Master..spt_Values 
    WHERE Number &gt; 0 and number &lt;= LEN(@str)
)as t</pre> </p>
<p><strong><code>Please try the different solution for this puzzle and share it via comment...</code></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/11/sql-puzzle-sql-advance-query-find-the-count-of-lowercase-uppercase-special-characters/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Puzzle: SQL Advance Query &#8211; Split the String and generate count of Each part</title>
		<link>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part/</link>
					<comments>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 21 Oct 2017 16:16:10 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Advance Query]]></category>
		<category><![CDATA[SQL Interview]]></category>
		<category><![CDATA[SQL Problem]]></category>
		<category><![CDATA[SQL Programming]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6177</guid>

					<description><![CDATA[Check the below input data and expected output to split the string and generate a count of each string. Split the string by semi colon. Input Data: [crayon-6ab3eb5a4baea844023771/] Expected Output: [crayon-6ab3eb5a4baeb942842641/] Create a table with data: [crayon-6ab3eb5a4baec667086548/] Solution 1: [crayon-6ab3eb5a4baed502739337/] Please try the different solution for this puzzle and share it via comment...]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F10%2Fsql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Split%20the%20String%20and%20generate%20count%20of%20Each%20part" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F10%2Fsql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Split%20the%20String%20and%20generate%20count%20of%20Each%20part" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F10%2Fsql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Split%20the%20String%20and%20generate%20count%20of%20Each%20part" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F10%2Fsql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Split%20the%20String%20and%20generate%20count%20of%20Each%20part" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F10%2Fsql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Split%20the%20String%20and%20generate%20count%20of%20Each%20part" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F10%2Fsql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Split%20the%20String%20and%20generate%20count%20of%20Each%20part" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F10%2Fsql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part%2F&#038;title=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Split%20the%20String%20and%20generate%20count%20of%20Each%20part" data-a2a-url="https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part/" data-a2a-title="SQL Puzzle: SQL Advance Query – Split the String and generate count of Each part"></a></p><p>Check the below input data and expected output to split the string and generate a count of each string. Split the string by semi colon. </p>
<p><strong>Input Data:</strong></p>
<pre class="crayon-plain-tag">str1
--------------------
anvesh;dbrnd;blog
dbrnd;blog
dbrnd
blog;anvesh</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">StringName           StringCounts
-------------------- ------------
anvesh               2
blog                 3
dbrnd                3</pre> </p>
<p><strong>Create a table with data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_SplitData
(
    str1 VARCHAR(20)
)
GO
 
INSERT INTO tbl_SplitData (str1)
VALUES ('anvesh;dbrnd;blog'),('dbrnd;blog'),('dbrnd'),('blog;anvesh')
GO</pre> </p>
<p><strong>Solution 1:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	StringName
	,COUNT(*) StringCounts 
FROM
(
    SELECT  CAST(CONCAT('&lt;t&gt;' , REPLACE(str1, ';' , '&lt;/t&gt;&lt;t&gt;' ) , '&lt;/t&gt;' ) AS XML) Xmlcol FROM tbl_SplitData
) s
CROSS apply
(
    SELECT ProjectData.D.value('.', 'VARCHAR(20)') as StringName
    FROM s.xmlcol.nodes('t') as ProjectData(D)
)t
GROUP BY t.StringName</pre> </p>
<p><strong><code>Please try the different solution for this puzzle and share it via comment...</code></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-split-the-string-and-generate-count-of-each-part/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Puzzle: Write a Function to count the total number of word</title>
		<link>https://www.dbrnd.com/2017/09/sql-puzzle-write-a-function-to-count-the-total-number-of-word/</link>
					<comments>https://www.dbrnd.com/2017/09/sql-puzzle-write-a-function-to-count-the-total-number-of-word/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 11 Sep 2017 16:16:14 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Advance Query]]></category>
		<category><![CDATA[SQL Interview]]></category>
		<category><![CDATA[SQL Problem]]></category>
		<category><![CDATA[SQL Programming]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6057</guid>

					<description><![CDATA[Create a user defined function to count the total number of a word from the given string data. Sample function execution: [crayon-6ab3eb5a4bd71248765246/] Expected Output: [crayon-6ab3eb5a4bd72547903053/] User defined function: [crayon-6ab3eb5a4bd73295706780/] Please try the different solution for this puzzle and share it via comment...]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-puzzle-write-a-function-to-count-the-total-number-of-word%2F&amp;linkname=SQL%20Puzzle%3A%20Write%20a%20Function%20to%20count%20the%20total%20number%20of%20word" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-puzzle-write-a-function-to-count-the-total-number-of-word%2F&amp;linkname=SQL%20Puzzle%3A%20Write%20a%20Function%20to%20count%20the%20total%20number%20of%20word" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-puzzle-write-a-function-to-count-the-total-number-of-word%2F&amp;linkname=SQL%20Puzzle%3A%20Write%20a%20Function%20to%20count%20the%20total%20number%20of%20word" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-puzzle-write-a-function-to-count-the-total-number-of-word%2F&amp;linkname=SQL%20Puzzle%3A%20Write%20a%20Function%20to%20count%20the%20total%20number%20of%20word" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-puzzle-write-a-function-to-count-the-total-number-of-word%2F&amp;linkname=SQL%20Puzzle%3A%20Write%20a%20Function%20to%20count%20the%20total%20number%20of%20word" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-puzzle-write-a-function-to-count-the-total-number-of-word%2F&amp;linkname=SQL%20Puzzle%3A%20Write%20a%20Function%20to%20count%20the%20total%20number%20of%20word" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-puzzle-write-a-function-to-count-the-total-number-of-word%2F&#038;title=SQL%20Puzzle%3A%20Write%20a%20Function%20to%20count%20the%20total%20number%20of%20word" data-a2a-url="https://www.dbrnd.com/2017/09/sql-puzzle-write-a-function-to-count-the-total-number-of-word/" data-a2a-title="SQL Puzzle: Write a Function to count the total number of word"></a></p><p>Create a user defined function to count the total number of a word from the given string data.</p>
<p><strong>Sample function execution:</strong></p>
<pre class="crayon-plain-tag">select [dbo].[fn_GetWordCount]('I am Database Engineer and I am the owner of dbrnd.com') AS TotalWordCount</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">TotalWordCount
--------------
11</pre> </p>
<p><strong>User defined function:</strong></p>
<pre class="crayon-plain-tag">CREATE FUNCTION [dbo].[fn_GetWordCount] (@InputStringData VARCHAR(100)) 
RETURNS INT
AS
BEGIN

DECLARE @i INT
DECLARE @Char CHAR(1)
DECLARE @PrevChar CHAR(1)
DECLARE @Counter INT

SET @i = 1
SET @Counter = 0

WHILE @i &lt;= LEN(@InputStringData)
BEGIN
    SET @Char = SUBSTRING(@InputStringData, @i, 1)
    SET @PrevChar = CASE WHEN @i = 1 THEN ' '
                         ELSE SUBSTRING(@InputStringData, @i - 1, 1)
                    END
    IF @PrevChar = ' ' AND @Char != ' '
    SET @Counter = @Counter + 1
    SET @i = @i + 1
END

RETURN @Counter 
END
GO</pre> </p>
<p><strong><code>Please try the different solution for this puzzle and share it via comment...</code></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/09/sql-puzzle-write-a-function-to-count-the-total-number-of-word/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: STRING_AGG() to Concatenate String Per Each Group (Like SQL Server STUFF())</title>
		<link>https://www.dbrnd.com/2016/09/postgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function/</link>
					<comments>https://www.dbrnd.com/2016/09/postgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 02 Sep 2016 07:47:41 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[aggregation]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[string concatenate]]></category>
		<category><![CDATA[string_agg]]></category>
		<category><![CDATA[stuff]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3569</guid>

					<description><![CDATA[Last week on my Facebook Page, I have received a couple message about what is a similar solution of SQL Server STUFF () in PostgreSQL. Most of the Database Developers require to perform String Aggregation based on different group of records. Since PostgreSQL 9.0, STRING_AGG(expression, delimiter) function is available to perform String Aggregation operation. Using [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fpostgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function%2F&amp;linkname=PostgreSQL%3A%20STRING_AGG%28%29%20to%20Concatenate%20String%20Per%20Each%20Group%20%28Like%20SQL%20Server%20STUFF%28%29%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fpostgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function%2F&amp;linkname=PostgreSQL%3A%20STRING_AGG%28%29%20to%20Concatenate%20String%20Per%20Each%20Group%20%28Like%20SQL%20Server%20STUFF%28%29%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fpostgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function%2F&amp;linkname=PostgreSQL%3A%20STRING_AGG%28%29%20to%20Concatenate%20String%20Per%20Each%20Group%20%28Like%20SQL%20Server%20STUFF%28%29%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fpostgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function%2F&amp;linkname=PostgreSQL%3A%20STRING_AGG%28%29%20to%20Concatenate%20String%20Per%20Each%20Group%20%28Like%20SQL%20Server%20STUFF%28%29%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fpostgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function%2F&amp;linkname=PostgreSQL%3A%20STRING_AGG%28%29%20to%20Concatenate%20String%20Per%20Each%20Group%20%28Like%20SQL%20Server%20STUFF%28%29%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fpostgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function%2F&amp;linkname=PostgreSQL%3A%20STRING_AGG%28%29%20to%20Concatenate%20String%20Per%20Each%20Group%20%28Like%20SQL%20Server%20STUFF%28%29%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fpostgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function%2F&#038;title=PostgreSQL%3A%20STRING_AGG%28%29%20to%20Concatenate%20String%20Per%20Each%20Group%20%28Like%20SQL%20Server%20STUFF%28%29%29" data-a2a-url="https://www.dbrnd.com/2016/09/postgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function/" data-a2a-title="PostgreSQL: STRING_AGG() to Concatenate String Per Each Group (Like SQL Server STUFF())"></a></p><p>Last week on my Facebook Page, I have received a couple message about what is a similar solution of SQL Server STUFF () in PostgreSQL. </p>
<p>Most of the Database Developers require to perform String Aggregation based on different group of records. </p>
<blockquote><p>Since PostgreSQL 9.0, STRING_AGG(expression, delimiter) function is available to perform String Aggregation operation.<br />
Using STRING_AGG(), We can concatenate strings using different type of delimiter symbols. </p></blockquote>
<p><strong>Example of STRING_AGG():</strong></p>
<p><strong>Create a sample Students table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	StudID INT 
	,StudName CHARACTER VARYING
	,StudGrades CHAR(1)
);</pre> </p>
<p><strong>Insert few sample records:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Students 
VALUES 
(1,'Anvesh','A'),(2,'Kimly','B')
,(3,'Jenny','C'),(4,'Ali','B')
,(5,'Mukesh','D'),(6,'Sofia','A')
,(7,'Roy','C'),(8,'Martin','C');</pre> </p>
<p><strong>Concatenate Students Name per each Student Grade and arrange by Grade wise row (Using STRING_AGG()):</strong></p>
<pre class="crayon-plain-tag">SELECT 	
	StudGrades
	,STRING_AGG(StudName,', ') AS StudPerGrade
FROM tbl_Students
GROUP BY StudGrades
ORDER BY 1 ;</pre> </p>
<p><strong>The Result:</strong></p>
<pre class="crayon-plain-tag">studgrades |    studpergrade
------------+--------------------
 A          | Anvesh, Sofia
 B          | Kimly, Ali
 C          | Jenny, Roy, Martin
 D          | Mukesh
(4 rows)</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/09/postgresql-string_agg-to-concatenate-string-per-each-group-like-sql-server-stuff-string-aggregation-function/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL: Perform Case Sensitive string comparison</title>
		<link>https://www.dbrnd.com/2016/02/mysql-perform-case-sensitive-string-comparison/</link>
					<comments>https://www.dbrnd.com/2016/02/mysql-perform-case-sensitive-string-comparison/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 10 Feb 2016 17:58:27 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[case-sensitive]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[LIKE BINARY]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1514</guid>

					<description><![CDATA[In this post, I am sharing a small demonstration on how to perform case-sensitive string comparison in MySQL. For example, if you are searching string with LIKE &#8216;a%&#8217;, also you get all records of LIKE &#8216;A%&#8217; &#8211; the reason is the case-insensitive comparison. By default, string comparisons are case insensitive because strings are non-binary. For [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-perform-case-sensitive-string-comparison%2F&amp;linkname=MySQL%3A%20Perform%20Case%20Sensitive%20string%20comparison" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-perform-case-sensitive-string-comparison%2F&amp;linkname=MySQL%3A%20Perform%20Case%20Sensitive%20string%20comparison" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-perform-case-sensitive-string-comparison%2F&amp;linkname=MySQL%3A%20Perform%20Case%20Sensitive%20string%20comparison" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-perform-case-sensitive-string-comparison%2F&amp;linkname=MySQL%3A%20Perform%20Case%20Sensitive%20string%20comparison" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-perform-case-sensitive-string-comparison%2F&amp;linkname=MySQL%3A%20Perform%20Case%20Sensitive%20string%20comparison" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-perform-case-sensitive-string-comparison%2F&amp;linkname=MySQL%3A%20Perform%20Case%20Sensitive%20string%20comparison" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-perform-case-sensitive-string-comparison%2F&#038;title=MySQL%3A%20Perform%20Case%20Sensitive%20string%20comparison" data-a2a-url="https://www.dbrnd.com/2016/02/mysql-perform-case-sensitive-string-comparison/" data-a2a-title="MySQL: Perform Case Sensitive string comparison"></a></p><p>In this post, I am sharing a small demonstration on how to perform case-sensitive string comparison in MySQL. </p>
<p>For example, if you are searching string with LIKE &#8216;a%&#8217;, also you get all records of LIKE &#8216;A%&#8217; &#8211; the reason is the case-insensitive comparison.<br />
By default, string comparisons are case insensitive because strings are non-binary. For the case-sensitive comparison, we should use binary collation. </p>
<blockquote><p>If you need case-sensitive string comparison, you should use this COLLATION latin1_bin.</p>
<p><strong><code><a href="https://www.dbrnd.com/2015/10/mysql-how-to-change-default-character-set-to-utf-8/" target="_blank">You can visit this article about, How to change default COLLATION in MySQL. </a><br />
</code></strong></p></blockquote>
<p><strong>The String Case Sensitive Comparison using LIKE BINARY:</strong></p>
<p>You can also perform string case-sensitive comparison using LIKE BINARY operator.<br />
Generally, we need for password comparison.</p>
<p>Below is a full demonstration on this:</p>
<p><strong>Create a sample table and data: </strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
    StudentID INT AUTO_INCREMENT
    ,StudentName VARCHAR(255)
    ,CONSTRAINT pk_tbl_Students_StudentID PRIMARY KEY (StudentID)
);

INSERT INTO tbl_Students (StudentName) 
VALUES ('Anvesh'),('Roy'),('martin'),('Loris'),('Jenny');</pre> </p>
<p><strong>Execute below three queries and check the result:<br />
</strong>Using normal LIKE you will get Case insensitive result and using LIKE BINARY you will get the Case sensitive result. </p>
<pre class="crayon-plain-tag">SELECT 
    StudentID
    ,StudentName
FROM tbl_Students WHERE StudentName LIKE 'roy';
-- Return one record of Student 'Roy'

SELECT 
    StudentID
    ,StudentName
FROM tbl_Students WHERE StudentName LIKE BINARY 'roy';
-- No record for Student 'roy' because this is case sensitive check,'roy' and 'Roy' both are different. 

SELECT 
    StudentID
    ,StudentName
FROM tbl_Students WHERE StudentName LIKE BINARY 'Roy';
-- Return one record of Student 'Roy'</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/mysql-perform-case-sensitive-string-comparison/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
