<?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>Solomon &#187; SQL Server</title>
	<atom:link href="http://www.ms.oyangudi.com/blog/category/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ms.oyangudi.com/blog</link>
	<description>from Oyangudi...</description>
	<lastBuildDate>Sat, 21 Aug 2010 11:35:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Comma Delimited Output &#8211; single select statement &#8211; SQL Server</title>
		<link>http://www.ms.oyangudi.com/blog/sql-server/comma-delimited-output-single-select-statement-sql-server/</link>
		<comments>http://www.ms.oyangudi.com/blog/sql-server/comma-delimited-output-single-select-statement-sql-server/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 11:07:14 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/sql-server/comma-delimited-output-single-select-statement-sql-server/</guid>
		<description><![CDATA[&#160; We can get a comma delimited output from a single select statement in SQL Server by using the following SQL Script. select stuff(( select ',' + CountryRegionCode from Person.CountryRegion for xml path('') ), 1, 1, '') as CodeList &#160;]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>We can get a comma delimited output from a single select statement in SQL Server by using the following SQL Script.</p>
<pre class="brush: sql;">

select  stuff(( select  ',' + CountryRegionCode
                from    Person.CountryRegion
              for
                xml path('')
              ), 1, 1, '') as CodeList
</pre>
<p>&#160;</p>
<p><a href="http://www.ms.oyangudi.com/blog/wp-content/uploads/CommaDelimitedOutputsingleselectstatemen_E9A3/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/CommaDelimitedOutputsingleselectstatemen_E9A3/image_thumb.png" width="611" height="587" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/sql-server/comma-delimited-output-single-select-statement-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comma-Delimited Output (SQL Server)</title>
		<link>http://www.ms.oyangudi.com/blog/sql-server/comma-delimited-output-sql-server/</link>
		<comments>http://www.ms.oyangudi.com/blog/sql-server/comma-delimited-output-sql-server/#comments</comments>
		<pubDate>Sat, 02 May 2009 10:26:00 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Comma-Delimited Output]]></category>
		<category><![CDATA[Comma-Seperated Output]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=45</guid>
		<description><![CDATA[Using Query: use Northwind GO declare @CustIDs varchar(8000) select top 10 @CustIDs = isnull(@CustIDs + ',', '') + CustomerID from Customers select @CustIDs GO Using Cursor: declare cCustomerIDs cursor for select [CustomerID] from [dbo].[Customers] order by [CustomerID] declare @CustomerIDs varchar(8000) declare @CustomerID varchar(10) open cCustomerIDs fetch next from cCustomerIDs into @CustomerID while @@FETCH_STATUS = 0 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Using Query:</strong></p>
<pre class="brush: sql;">

use Northwind
GO

declare @CustIDs varchar(8000)

select top 10
        @CustIDs = isnull(@CustIDs + ',', '') + CustomerID
from    Customers

select  @CustIDs

GO
</pre>
<p><strong>Using Cursor:</strong></p>
<pre class="brush: sql;">

declare cCustomerIDs cursor for

select [CustomerID] from [dbo].[Customers] order by [CustomerID]

declare @CustomerIDs varchar(8000)

declare @CustomerID varchar(10)

open cCustomerIDs

fetch next from cCustomerIDs into @CustomerID

while @@FETCH_STATUS = 0
    begin

        set @CustomerIDs = isnull(@CustomerIDs + ',', '') + @CustomerID

        fetch next from cCustomerIDs into @CustomerID

    end

close cCustomerIDs

deallocate cCustomerIDs

select  @CustomerIDs as CustomerIDs

GO
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/sql-server/comma-delimited-output-sql-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find the balance amount (sum(credit) &#8211; sum(debit)) from the following table?</title>
		<link>http://www.ms.oyangudi.com/blog/sql-server/find-the-balance-amount-sum-credit-sum-debit-from-the-following-table/</link>
		<comments>http://www.ms.oyangudi.com/blog/sql-server/find-the-balance-amount-sum-credit-sum-debit-from-the-following-table/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 04:44:11 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=29</guid>
		<description><![CDATA[Ans: find out the balance amount of account no: 1 select a.SumCr as Credit , b.SumDr as Debit , a.SumCr - b.SumDr as Balance from ( select sum(A_Amount) as SumCr from tblAccount where A_ID = 1 and A_Type = 'Cr' ) a , ( select sum(A_Amount) as SumDr from tblAccount where A_ID = 1 and [...]]]></description>
			<content:encoded><![CDATA[<p><strong><img style="display: inline; border: 0px;" title="acc_balance" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/Findthebalanceamountsumcreditsumdebitfro_14F94/acc_balance.gif" border="0" alt="acc_balance" width="440" height="336" /> </strong></p>
<p>  <strong>Ans: find out the balance amount of account no: 1</strong>
</p>
<pre class="brush: sql;">

select  a.SumCr as Credit ,
        b.SumDr as Debit ,
        a.SumCr - b.SumDr as Balance
from    ( select    sum(A_Amount) as SumCr
          from      tblAccount
          where     A_ID = 1
                    and A_Type = 'Cr'
        ) a ,
        ( select    sum(A_Amount) as SumDr
          from      tblAccount
          where     A_ID = 1
                    and A_Type = 'Dr'
        ) b
</pre>
<p><strong><img style="display: inline; border: 0px;" title="acc_balance-result1" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/Findthebalanceamountsumcreditsumdebitfro_14F94/acc_balanceresult1.gif" border="0" alt="acc_balance-result1" width="537" height="420" /> </strong>
</p>
<p><strong>Ans: find out the balance amount for all the account numbers in the table:</strong>
</p>
<pre class="brush: sql;">

select  a.A_ID as ID ,
        a.SumCr as Credit ,
        b.SumDr as Debit ,
        a.SumCr - b.SumDr as Balance
from    ( select    A_ID ,
                    sum(A_Amount) as SumCr
          from      tblAccount
          where     A_Type = 'Cr'
          group by  A_ID
        ) a
        inner join ( select A_ID ,
                            sum(A_Amount) as SumDr
                     from   tblAccount
                     where  A_Type = 'Dr'
                     group by A_ID
                   ) b on a.A_ID = b.A_ID
</pre>
<p><img style="display: inline; border: 0px;" title="acc_balance-result2" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/Findthebalanceamountsumcreditsumdebitfro_14F94/acc_balanceresult2.gif" border="0" alt="acc_balance-result2" width="548" height="539" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/sql-server/find-the-balance-amount-sum-credit-sum-debit-from-the-following-table/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find out the N&#8217;th maxium salary?</title>
		<link>http://www.ms.oyangudi.com/blog/sql-server/find-out-the-n-th-maxium-salary/</link>
		<comments>http://www.ms.oyangudi.com/blog/sql-server/find-out-the-n-th-maxium-salary/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 04:42:25 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[nth Maximum]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=28</guid>
		<description><![CDATA[Ans: find the 5th maxium salary: 1: SELECT TOP 1 * FROM tblEmployee WHERE E_Salary NOT IN 2: (SELECT DISTINCT TOP 4 E_Salary FROM tblEmployee ORDER BY E_Salary DESC) 3: ORDER BY E_Salary DESC]]></description>
			<content:encoded><![CDATA[<p><strong><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="nth-maximum" border="0" alt="nth-maximum" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/FindouttheNthmaxiumsalary_14D2E/nthmaximum.gif" width="514" height="440" /> </strong></p>
<p><strong>Ans: find the 5<sup>th</sup> maxium salary: </strong></p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> <span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">TOP</span> 1 * <span style="color: #0000ff">FROM</span> tblEmployee <span style="color: #0000ff">WHERE</span> E_Salary <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">IN</span> </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span>     (<span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">DISTINCT</span> <span style="color: #0000ff">TOP</span> 4 E_Salary <span style="color: #0000ff">FROM</span> tblEmployee <span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> E_Salary <span style="color: #0000ff">DESC</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> E_Salary <span style="color: #0000ff">DESC</span></pre>
</p></div>
</div>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="nth-maximum-result" border="0" alt="nth-maximum-result" src="http://www.ms.oyangudi.com/blog/wp-content/uploads/FindouttheNthmaxiumsalary_14D2E/nthmaximumresult.gif" width="580" height="271" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/sql-server/find-out-the-n-th-maxium-salary/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
