<?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>stuff &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/stuff/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, 09 Mar 2018 06:46:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Puzzle: SQL Advance Query &#8211; Concat the String records without using STUFF function</title>
		<link>https://www.dbrnd.com/2018/03/sql-puzzle-concat-the-string-records-without-using-stuff-function/</link>
					<comments>https://www.dbrnd.com/2018/03/sql-puzzle-concat-the-string-records-without-using-stuff-function/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 13 Mar 2018 16:16:46 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[CONCAT]]></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[stuff]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7217</guid>

					<description><![CDATA[Check the below input data and expected output and concat the string data without using STUFF function. Input Data: [crayon-6aabf96b3dafa059578118/] Expected Output: [crayon-6aabf96b3db00367535795/] Create a table with sample data: [crayon-6aabf96b3db01174647112/] Solution by creating a function: [crayon-6aabf96b3db02646279276/] 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%2F2018%2F03%2Fsql-puzzle-concat-the-string-records-without-using-stuff-function%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Concat%20the%20String%20records%20without%20using%20STUFF%20function" 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%2F2018%2F03%2Fsql-puzzle-concat-the-string-records-without-using-stuff-function%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Concat%20the%20String%20records%20without%20using%20STUFF%20function" 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%2F2018%2F03%2Fsql-puzzle-concat-the-string-records-without-using-stuff-function%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Concat%20the%20String%20records%20without%20using%20STUFF%20function" 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%2F2018%2F03%2Fsql-puzzle-concat-the-string-records-without-using-stuff-function%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Concat%20the%20String%20records%20without%20using%20STUFF%20function" 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%2F2018%2F03%2Fsql-puzzle-concat-the-string-records-without-using-stuff-function%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Concat%20the%20String%20records%20without%20using%20STUFF%20function" 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%2F2018%2F03%2Fsql-puzzle-concat-the-string-records-without-using-stuff-function%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Concat%20the%20String%20records%20without%20using%20STUFF%20function" 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%2F2018%2F03%2Fsql-puzzle-concat-the-string-records-without-using-stuff-function%2F&#038;title=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Concat%20the%20String%20records%20without%20using%20STUFF%20function" data-a2a-url="https://www.dbrnd.com/2018/03/sql-puzzle-concat-the-string-records-without-using-stuff-function/" data-a2a-title="SQL Puzzle: SQL Advance Query – Concat the String records without using STUFF function"></a></p><p>Check the below input data and expected output and concat the string data without using STUFF function.</p>
<p><strong>Input Data:</strong></p>
<pre class="crayon-plain-tag">id          strname
----------- ------------
1           a
1           b
1           c
2           x
2           y
3           p
3           q
3           r</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">id          ConcatString
----------- ---------------
1           a, b, c
2           x, y
3           p, q, r</pre> </p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_strings (id int, strname varchar(50))
GO

INSERT INTO tbl_strings VALUES 
(1,'a'),(1,'b'),(1,'c')
,(2,'x'),(2,'y')
,(3,'p'),(3,'q'),(3,'r')
GO</pre> </p>
<p><strong>Solution by creating a function:</strong></p>
<pre class="crayon-plain-tag">CREATE FUNCTION [dbo].[GetConcatString]
(
    @id int
)
RETURNS varchar(max)
AS
BEGIN
    DECLARE @str VARCHAR(max)
    SELECT @str = COALESCE(@str + ', ', '') + strname
    FROM tbl_strings
    WHERE id = @id
    RETURN @str
END
GO

SELECT id, dbo.GetConcatString(id) as ConcatString
FROM tbl_strings
GROUP BY id
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/2018/03/sql-puzzle-concat-the-string-records-without-using-stuff-function/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Puzzle: SQL Advance Query &#8211; Use STUFF() and form the aggregate of columns</title>
		<link>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns/</link>
					<comments>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 20 Oct 2017 16:16:17 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[aggregate]]></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[stuff]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5841</guid>

					<description><![CDATA[Check the below input data and expected output to merge the driven car&#8217;s data like which car has driven by which drivers and form the aggregate the result for the same car. Input Data: [crayon-6aabf96b3dfa6557088287/] Expected Output: [crayon-6aabf96b3dfa9710886855/] Create a table with sample data: [crayon-6aabf96b3dfaa228790324/] Solution: [crayon-6aabf96b3dfab028174469/] Please try the different solutions for this puzzle [&#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%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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-use-stuff-and-form-the-aggregate-of-columns%2F&#038;title=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" data-a2a-url="https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns/" data-a2a-title="SQL Puzzle: SQL Advance Query – Use STUFF() and form the aggregate of columns"></a></p><p>Check the below input data and expected output to merge the driven car&#8217;s data like which car has driven by which drivers and form the aggregate the result for the same car.</p>
<p><strong>Input Data:</strong></p>
<pre class="crayon-plain-tag">CarName    Rout                 Driver     Year
---------- -------------------- ---------- -----------
Mobilio    hyd - ahd            Anvesh     2017
HCity      ahd - raj            Mukesh     2016
Mobilio    kadi - abu           Mukesh     2016
Duster     mha - dlh            Nupur      2017
Duster     hyd - ahd            Anvesh     2016
Duster     bha - ahd            Manish     2015</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">CarName    DrivenDetails
---------- ------------------------------------------------------------------------------------------------------
Duster     Rout:mha - dlh, driven by Nupur in Year  2017, Rout:hyd - ahd, driven by Anvesh in Year  2016, Rout:bha - ahd, driven by Manish in Year  2015
HCity      Rout:ahd - raj, driven by Mukesh in Year  2016
Mobilio    Rout:hyd - ahd, driven by Anvesh in Year  2017, Rout:kadi - abu, driven by Mukesh in Year  2016</pre> </p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE Cars 
(
	CarName VARCHAR(10)
	,Rout VARCHAR(20)
	,Driver VARCHAR(10)
	,Year INT
)
GO
 
INSERT INTO Cars VALUES
('Mobilio','hyd - ahd', 'Anvesh',2017)
,('HCity','ahd - raj', 'Mukesh',2016)
,('Mobilio','kadi - abu', 'Mukesh',2016)
,('Duster','mha - dlh', 'Nupur',2017)
,('Duster','hyd - ahd', 'Anvesh',2016)
,('Duster','bha - ahd', 'Manish',2015)
GO</pre> </p>
<p><strong>Solution:</strong></p>
<pre class="crayon-plain-tag">SELECT b.CarName 
	,STUFF 
	((
	SELECT ', Rout:' + Rout + ', driven by ' + CAST(Driver AS VARCHAR(MAX)) + ' in Year  ' + CAST(Year AS VARCHAR(MAX))
	FROM Cars a
	WHERE ( a.CarName = b.CarName )
	FOR XML PATH('')
	) ,1,2,'') 
	AS DrivenDetails
FROM Cars b
GROUP BY b.CarName</pre> </p>
<p><strong><code>Please try the different solutions 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-use-stuff-and-form-the-aggregate-of-columns/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Puzzle: SQL Advance Query &#8211; Use STUFF() and Mask the Credit Card Number</title>
		<link>https://www.dbrnd.com/2017/08/sql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number/</link>
					<comments>https://www.dbrnd.com/2017/08/sql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 28 Aug 2017 16:16:43 +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[Mask]]></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[stuff]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5993</guid>

					<description><![CDATA[Check the below input data and expected output to Mask the Credit Card Number. Sample Credit Card Number: [crayon-6aabf96b3e181414749903/] Expected Output: [crayon-6aabf96b3e184141161416/] Solution: [crayon-6aabf96b3e185022610416/] 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%2F08%2Fsql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20Mask%20the%20Credit%20Card%20Number" 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%2F08%2Fsql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20Mask%20the%20Credit%20Card%20Number" 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%2F08%2Fsql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20Mask%20the%20Credit%20Card%20Number" 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%2F08%2Fsql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20Mask%20the%20Credit%20Card%20Number" 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%2F08%2Fsql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20Mask%20the%20Credit%20Card%20Number" 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%2F08%2Fsql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20Mask%20the%20Credit%20Card%20Number" 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%2F08%2Fsql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number%2F&#038;title=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20Mask%20the%20Credit%20Card%20Number" data-a2a-url="https://www.dbrnd.com/2017/08/sql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number/" data-a2a-title="SQL Puzzle: SQL Advance Query – Use STUFF() and Mask the Credit Card Number"></a></p><p>Check the below input data and expected output to Mask the Credit Card Number.</p>
<p><strong>Sample Credit Card Number:</strong></p>
<pre class="crayon-plain-tag">8168888888521458</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">Result
--------------------
XXXXXXXXXXXX1458</pre> </p>
<p><strong>Solution:</strong></p><pre class="crayon-plain-tag">DECLARE @CreditCardNo VARCHAR(20)
SET @CreditCardNo = '8168888888521458'

SELECT STUFF(@CreditCardNo, 1, LEN(@CreditCardNo) - 4,
REPLICATE('X', LEN(@CreditCardNo) - 4)) AS Result</pre><p> </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/08/sql-puzzle-sql-advance-query-use-stuff-and-mask-the-credit-card-number/feed/</wfw:commentRss>
			<slash:comments>1</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>SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-16)</title>
		<link>https://www.dbrnd.com/2016/06/ql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 27 Jun 2016 20:33:41 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Developer]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[DBCC SHOWCONTIG]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Interviews]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[stuff]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tempdb storage]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[XML Operations]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3088</guid>

					<description><![CDATA[What are the useful DMVs for TempDB? dm_db_file_space_usage: Stores metadata about disk space usage statistics by “user object”, “internal objects” and “version store” dm_db_session_space_usage: Stores metadata about disk space usage, page allocation and deallocation statistics at user session level. dm_db_task_space_usage: Stores metadata about disk space usage, page allocation and deallocation statistics at session task level. [&#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%2F06%2Fql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-16%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%2F06%2Fql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-16%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%2F06%2Fql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-16%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%2F06%2Fql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-16%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%2F06%2Fql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-16%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%2F06%2Fql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-16%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%2F06%2Fql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16%2F&#038;title=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-16%29" data-a2a-url="https://www.dbrnd.com/2016/06/ql-server-database-developer-t-sql-interview-questions-and-answers-tempdb-storage-dbcc-showcontig-stuff-replace-day-16/" data-a2a-title="SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-16)"></a></p><p><strong>What are the useful DMVs for TempDB?</strong></p>
<ul>
<li>dm_db_file_space_usage: Stores metadata about disk space usage statistics by “user object”, “internal objects” and “version store”</li>
<li>dm_db_session_space_usage: Stores metadata about disk space usage, page allocation and deallocation statistics at user session level.</li>
<li>dm_db_task_space_usage: Stores metadata about disk space usage, page allocation and deallocation statistics at session task level.</li>
<li>dm_tran_active_snapshot_database_transactions: its returns a virtual table for all active transaction running in tempdb</li>
</ul>
<p><strong>What kind of different objects SQL Server stores in the TempDB?</strong></p>
<p><strong>User Objects:</strong></p>
<ul>
<li>Table variables</li>
<li>Table valued functions</li>
<li>Local and Global temporary variables</li>
<li>Local and Global Temporary Indexes</li>
<li>Temp Stored procedure</li>
<li>User defined table</li>
<li>User defined Index</li>
<li>Global table</li>
<li>System Index</li>
</ul>
<p><strong>Internal Objects:</strong></p>
<ul>
<li>Cursor’s worktable</li>
<li>Temporary Large object (LOB) storage</li>
<li>DISTINCT, ORDER BY, GROUP BY and UNION</li>
<li>Rebuilding Index with SORT_IN_TEMPDB options</li>
<li>HASH JOIN</li>
<li>Multiple active result set (MARS)</li>
</ul>
<p><strong>Database Engine spool:</strong></p>
<ul>
<li>Lazy Spool</li>
<li>Eager Spool</li>
<li>Index Spool</li>
<li>Table Spool</li>
<li>Row Count Spool</li>
<li>Window Spool</li>
</ul>
<p><strong>Version Store:</strong></p>
<ul>
<li>DML operation that use row versioning</li>
<li>Index rebuild that use row versioning</li>
</ul>
<p><strong>How to find minimum, maximum and average row size in each table in SQL server?</strong></p>
<blockquote><p>Using DBCC SHOWCONTIG, we can find minimum, maximum and average row size of table.</p>
<p><strong>Query to get result for all the table:</strong></p><pre class="crayon-plain-tag">DBCC SHOWCONTIG WITH TABLERESULTS</pre><p>
<strong>Query to get result for a specific table:</strong></p><pre class="crayon-plain-tag">DBCC SHOWCONTIG([dbo].[TableName]) with TABLERESULTS</pre><p>
</p></blockquote>
<p><strong>What are the new features introduced in SQL Server 2014?</strong></p>
<ul>
<li>Buffer pool extensions to SSD</li>
<li>In-memory OLTP</li>
<li>IN-memory DW</li>
<li>Delayed Durability</li>
<li>SQL Server datafile in window Azure</li>
<li>Clustered Columnstore Index</li>
<li>Better Statistics per partition</li>
<li>Parallel SELECT INTO</li>
<li>Rebuild Blob index ONLINE</li>
<li>Backup Encryption</li>
</ul>
<p><strong>What are the new features introduced in SQL Server 2012?</strong></p>
<p><strong>New Features related to database administration: </strong></p>
<ul>
<li>Always on features which is actually High availability and Disaster recovery solution</li>
<li>Always on SQL Failover Clustering (FCI) across multi domain</li>
<li>Always on Availability group</li>
<li>Contained database</li>
<li>Column store Index</li>
<li>User defined server role</li>
<li>Distributed replay</li>
<li>Statistical Semantic Search</li>
<li>Added few DMVs like sys.dm_os_volumn_stats, sys.dm_os_windows_info, sys.dm_server_memory_dumps, sys.dm_server_services and sys.dm_server_registry</li>
<li>15000 Partitioned table can be created now from previously 1000 limit.</li>
</ul>
<p><strong>New features related T-SQL:</strong></p>
<ul>
<li>Sequence Object</li>
<li>File table</li>
<li>Logical Function CHOOSE and IIF</li>
<li>Conversion function PARSE, TRY_CONVERT and TRY_PARSE</li>
<li>Date and Time function DATEFORMATS, DATETIME2FORMATS, DATETIMEFORMATS, DATETIMEOFFSETFORMATS, EOMONTHS, SMALLDATETIMEFORMATS and TIMEFROMPARTS</li>
<li>String functions CONCAT and FORMAT</li>
<li>Analytic Function CUME_DIST, FIRST_VALUE, LAST_VALUE, LAG, LEAD, PERCENTILE_CONT, PERCENTILE_DISC and PERCENT_RANK</li>
<li>OFFSET and FETCH key work introduced for SELECT statement</li>
<li>ONLINE rebuild option is available now for LOB column type too</li>
</ul>
<p><strong>How to get Only Hour, Minute and Second from the datetime column?</strong></p><pre class="crayon-plain-tag">select substring(convert(char(20),getdate(),109), 14, 7) as HourMinute</pre><p>
<strong>What is SET ANSI WARNING on?</strong></p>
<blockquote><p>When on it displays the warning if there Is any null value for operations such as group by, order by max etc. and also if there is an arithmetic over flow. When off its displays no warning and also truncates the data to fit in the size of the column.</p></blockquote>
<p><strong>What’s wrong in the following query?</strong></p>
<p><strong>SELECT subject_code, AVG (marks) FROM students WHERE AVG(marks) &gt; 88 GROUP BY subject_code;</strong></p>
<blockquote><p>The WHERE clause cannot be used to restrict groups. The HAVING clause should be used.</p></blockquote>
<p><strong>What’s wrong in the following query?</strong></p>
<p><strong>SELECT subject_code, count(name) FROM students;</strong></p>
<blockquote><p>It doesn’t have a GROUP BY clause. The subject_code should be in the GROUP BY clause.</p></blockquote>
<p><strong>What is the difference between SUBSTR and INSTR in the SQL Server?</strong></p>
<blockquote><p>The SUBSTR function is used to return specific portion of string in a given string. But, INSTR function gives character position in a given specified string.</p></blockquote>
<p><strong>What is the use of FOR Clause?</strong></p>
<blockquote><p>FOR clause is mainly used for XML and browser options. This clause is mainly used to display the query results in XML format or in browser.</p></blockquote>
<p><strong>What is the difference between COMMIT and ROLLBACK?</strong></p>
<blockquote><p>Every statement between BEGIN and COMMIT becomes persistent to database when the COMMIT is executed. Every statement between BEGIN and ROOLBACK are reverted to the state when the ROLLBACK was executed.</p></blockquote>
<p><strong>What is the difference between GETDATE and SYSDATETIME?</strong></p>
<blockquote><p>Both are same but GETDATE can give time till milliseconds and SYSDATETIME can give precision till nanoseconds. SYSDATE TIME is more accurate than GETDATE.</p></blockquote>
<p><strong>What is SQL injection?</strong></p>
<blockquote><p>SQL injection is an attack by malicious users in which malicious code can be inserted into strings that can be passed to an instance of SQL server for parsing and execution. All statements have to checked for vulnerabilities as it executes all syntactically valid queries that it receives.</p>
<p>Even parameters can be manipulated by the skilled and experienced attackers.</p></blockquote>
<p><strong>How to select unique records from a table?</strong></p>
<blockquote><p>Select unique records from a table by using DISTINCT keyword.</p>
<p>Select DISTINCT ColumnName from TableName;</p></blockquote>
<p><strong>How do you implement one-to-one, one-to-many and many-to-many relationships while designing tables?</strong></p>
<ul>
<li>One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships.</li>
<li>One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships.</li>
<li>Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.</li>
<li>It will be a good idea to read up a database designing fundamentals text book.</li>
</ul>
<p><strong>What is the STUFF Function and How Does it Differ from the REPLACE Function?</strong></p>
<blockquote><p>STUFF function is used to overwrite existing characters using this syntax: STUFF (string_expression, start, length, replacement_characters), where string_expression is the string that will have characters substituted, start is the starting position, length is the number of characters in the string that are substituted, and replacement_characters are the new characters interjected into the string.</p>
<p>REPLACE function is used to replace existing characters of all occurrences. Using the syntax REPLACE (string_expression, search_string, replacement_string), every incidence of search_string found in the string_expression will be replaced with replacement_string.</p></blockquote>
<p><strong>How to Enable/Disable Indexes?</strong></p><pre class="crayon-plain-tag">--Disable Index
ALTER INDEX [IndexName] ON TableName DISABLE
GO

--Enable Index
ALTER INDEX [IndexName] ON TableName REBUILD
GO</pre><p>
<strong>How do you solve performance problems with XML operations?</strong></p>
<blockquote><p>There are no ‘correct’ answers to generic performance questions. A proper solution can be suggested only after examining the specific use case and environment.  However, a few recommendations are as follows:</p>
<p>If you are dealing with UNTYPED XML, try to convert them to TYPED XML. When using TYPED XML values, SQL Server has got better understanding of the structure of the XML document, data types of elements and attributes etc.  This allows SQL Server to process the XML document more efficiently.</p>
<p>XML Indexes can be used to speed up queries that read information from XML data type columns.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
