<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>SQL Server help</title>
	<atom:link href="http://sqlhelp.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlhelp.wordpress.com</link>
	<description>Complete support for SQL Server, Visual Basic, Active Server Pages help</description>
	<lastBuildDate>Tue, 06 Dec 2011 16:20:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sqlhelp.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/9b770f7eeda80ffe3a2722ffa47d9ab4?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>SQL Server help</title>
		<link>http://sqlhelp.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sqlhelp.wordpress.com/osd.xml" title="SQL Server help" />
	<atom:link rel='hub' href='http://sqlhelp.wordpress.com/?pushpress=hub'/>
		<item>
		<title>HTTP Get method from MSSQL</title>
		<link>http://sqlhelp.wordpress.com/2011/08/14/http-get-method-from-mssql/</link>
		<comments>http://sqlhelp.wordpress.com/2011/08/14/http-get-method-from-mssql/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 11:25:39 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[HTTP Get method from MSSQL]]></category>
		<category><![CDATA[Advance MSSQL tips]]></category>
		<category><![CDATA[HTTP Method from SQL]]></category>
		<category><![CDATA[HTTP post]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[web api from MSSQL]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=486</guid>
		<description><![CDATA[If you want to call a URL and store the response of that url use this function: ALTER function [dbo].[GetHttp] ( @url varchar(8000) ) returns varchar(8000) as BEGIN DECLARE @win int DECLARE @hr  int DECLARE @text varchar(8000) EXEC @hr=sp_OACreate 'WinHttp.WinHttpRequest.5.1',@win OUT IF @hr &#60;&#62; 0 EXEC sp_OAGetErrorInfo @win EXEC @hr=sp_OAMethod @win, 'Open',NULL,'GET',@url,'false' IF @hr &#60;&#62; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=486&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>If you want to call a URL and store the response of that url use this function</strong>:<br />
<code><br />
ALTER function [dbo].[GetHttp]<br />
(<br />
@url varchar(8000)<br />
)<br />
returns varchar(8000)<br />
as<br />
BEGIN<br />
DECLARE @win int<br />
DECLARE @hr  int<br />
DECLARE @text varchar(8000)</code></p>
<p><code>EXEC @hr=sp_OACreate 'WinHttp.WinHttpRequest.5.1',@win OUT<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code><br />
<code><br />
EXEC @hr=sp_OAMethod @win, 'Open',NULL,'GET',@url,'false'<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OAMethod @win,'Send'<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OAGetProperty @win,'ResponseText',@text OUTPUT<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OADestroy @win<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>RETURN @text</code></p>
<p><code><br />
END</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/486/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=486&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2011/08/14/http-get-method-from-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Http Post from MSSQL</title>
		<link>http://sqlhelp.wordpress.com/2011/08/14/http-post-from-mssql/</link>
		<comments>http://sqlhelp.wordpress.com/2011/08/14/http-post-from-mssql/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 11:21:27 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Http Post from MSSQL]]></category>
		<category><![CDATA[Advance MSSQL tips]]></category>
		<category><![CDATA[HTTP post using MSSQL]]></category>
		<category><![CDATA[MSSQL HTTP Post]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[web api from MSSQL]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=484</guid>
		<description><![CDATA[Call the HTTP post using MSSQL script : ALTER function [dbo].[POSTHttp] ( @url varchar(8000), @data varchar(2000) ) returns varchar(8000) as BEGIN DECLARE @win int DECLARE @hr  int DECLARE @text varchar(8000) EXEC @hr=sp_OACreate 'WinHttp.WinHttpRequest.5.1',@win OUT IF @hr &#60;&#62; 0 EXEC sp_OAGetErrorInfo @win EXEC @hr=sp_OAMethod @win, 'Open',NULL,'POST',@url,'false' IF @hr &#60;&#62; 0 EXEC sp_OAGetErrorInfo @win EXEC @hr=sp_OAMethod @win, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=484&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong> Call the HTTP post using MSSQL script :<br />
</strong></p>
<p><strong><br />
</strong></p>
<p><code>ALTER function [dbo].[POSTHttp]<br />
(<br />
@url varchar(8000),<br />
@data varchar(2000)<br />
)<br />
returns varchar(8000)<br />
as</code></p>
<p><code>BEGIN<br />
DECLARE @win int<br />
DECLARE @hr  int<br />
DECLARE @text varchar(8000)</code><br />
<code><br />
EXEC @hr=sp_OACreate 'WinHttp.WinHttpRequest.5.1',@win OUT<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OAMethod @win, 'Open',NULL,'POST',@url,'false'<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OAMethod @win, 'setRequestHeader',NULL, 'Content-type'<br />
, 'application/x-www-form-urlencoded'<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OAMethod @win,'Send',null,@data<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OAGetProperty @win,'ResponseText',@text OUTPUT<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OAGetProperty @win,'ResponseText',@text OUTPUT<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win</code></p>
<p><code>EXEC @hr=sp_OADestroy @win<br />
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win<br />
</code><br />
<code>RETURN @text</code></p>
<p><code>END</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/484/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=484&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2011/08/14/http-post-from-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>CTE Function</title>
		<link>http://sqlhelp.wordpress.com/2011/05/06/cte-function/</link>
		<comments>http://sqlhelp.wordpress.com/2011/05/06/cte-function/#comments</comments>
		<pubDate>Fri, 06 May 2011 13:34:17 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[CTE Function]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=479</guid>
		<description><![CDATA[CTE fucntion can be used on this way: IF OBJECT_ID('tempdb..#dataList') IS NOT NULL DROP TABLE #dataList CREATE TABLE #dataList( id            INT ,name        VARCHAR(50) ,parent        INT ,ip            INT ) INSERT #dataList SELECT 1    id, 'Group1'        Name, 0 Parent, 0 ip UNION ALL SELECT 2    id, 'SubGroup1'        Name, 1 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=479&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>CTE fucntion can be used on this way:</strong></p>
<p><code>IF OBJECT_ID('tempdb..#dataList') IS NOT NULL<br />
DROP TABLE #dataList<br />
</code></p>
<p><code>CREATE TABLE #dataList(<br />
id            INT<br />
,name        VARCHAR(50)<br />
,parent        INT<br />
,ip            INT<br />
)</code></p>
<p><code><br />
INSERT #dataList<br />
SELECT 1    id, 'Group1'        Name, 0 Parent, 0 ip UNION ALL<br />
SELECT 2    id, 'SubGroup1'        Name, 1 Parent, 0 ip UNION ALL<br />
SELECT 3    id, 'Item1'            Name, 2 Parent, 1 ip UNION ALL<br />
SELECT 4    id, 'Item2'            Name, 2 Parent, 1 ip UNION ALL<br />
SELECT 5    id, 'Item3'            Name, 2 Parent, 1 ip UNION ALL<br />
SELECT 6    id, 'Item4'            Name, 2 Parent, 1 ip UNION ALL<br />
SELECT 7    id, 'SubGroup2'        Name, 1 Parent, 0 ip UNION ALL<br />
SELECT 8    id, 'Item5'            Name, 7 Parent, 1 ip UNION ALL<br />
SELECT 9    id, 'Item6'            Name, 7 Parent, 1 ip UNION ALL<br />
SELECT 10    id, 'Item7'            Name, 7 Parent, 1 ip UNION ALL<br />
SELECT 11    id, 'Item8'            Name, 7 Parent, 1 ip<br />
</code></p>
<p><code>--SELECT * FROM #dataList<br />
</code></p>
<p><code><br />
DECLARE @id INT = 1<br />
;WITH CTE(id, name, parent, ip)<br />
AS<br />
(<br />
SELECT * FROM #dataList WHERE id = @id<br />
UNION ALL<br />
SELECT d.* FROM #dataList D<br />
INNER JOIN CTE c ON d.parent = c.id<br />
)</code></p>
<p><code>SELECT * FROM CTE WHERE ip = 1 ORDER BY id ASC;</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/479/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=479&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2011/05/06/cte-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamic PIVOT</title>
		<link>http://sqlhelp.wordpress.com/2011/02/14/dynamic-pivot/</link>
		<comments>http://sqlhelp.wordpress.com/2011/02/14/dynamic-pivot/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 11:52:48 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Dynamic PIVOT]]></category>
		<category><![CDATA[Complex Cross Tab Result]]></category>
		<category><![CDATA[Customer and Loan Result from Cross Tab PIVOT]]></category>
		<category><![CDATA[Loan report]]></category>
		<category><![CDATA[MSSQL PIVOT]]></category>
		<category><![CDATA[PIVOT Query]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=465</guid>
		<description><![CDATA[Sample for Dynamic PIVOT Query: Some time we need complex cross tab result for report, that time we can use the PIVOT Query, for example we have 3 Tables and we have data like this : IF OBJECT_ID('tempdb..#customer') IS NOT NULL DROP TABLE #customer CREATE TABLE #customer ( CustomerId INT, CustomerName VARCHAR(50) ) INSERT #customer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=465&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Sample for Dynamic PIVOT Query:</strong></p>
<p>Some time we need complex cross tab result for report, that time we can use the PIVOT Query, for example we have 3 Tables and we have data like this :</p>
<p><code><br />
IF OBJECT_ID('tempdb..#customer') IS NOT NULL<br />
DROP  TABLE #customer</code></p>
<p><code>CREATE TABLE #customer (<br />
CustomerId  INT,<br />
CustomerName VARCHAR(50)<br />
)<br />
</code><br />
<code><br />
INSERT #customer<br />
SELECT 1,  'Ram'<br />
INSERT #customer<br />
SELECT 2, 'Hari'<br />
INSERT #customer<br />
SELECT 3,  'Depesh'<br />
INSERT #customer<br />
SELECT 4, 'Sailesh'</code></p>
<p><code>--Select * from  #customer</code></p>
<p><a href="http://sqlhelp.files.wordpress.com/2011/02/image31.jpg"><br />
<img class="alignnone size-full wp-image-471" title="image3" src="http://sqlhelp.files.wordpress.com/2011/02/image31.jpg?w=468" alt=""   /><br />
</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><code>IF OBJECT_ID('tempdb..#LoanType') IS NOT NULL<br />
DROP TABLE  #LoanType</code></p>
<p><code>CREATE TABLE #LoanType (<br />
LoanId INT,<br />
LoanName  VARCHAR(50)<br />
)</code><br />
<code><br />
INSERT #LoanType<br />
SELECT 1, 'Loan-1'<br />
INSERT  #LoanType<br />
SELECT 2, 'Loan-2'<br />
INSERT #LoanType<br />
SELECT 3,  'Loan-3'<br />
INSERT #LoanType<br />
SELECT 4, 'Loan-4'<br />
INSERT #LoanType<br />
SELECT  5, 'Loan-5'<br />
INSERT #LoanType<br />
SELECT 6, 'Loan-6'</code></p>
<p><code>--Select * from  #LoanType</code></p>
<p><a href="http://sqlhelp.files.wordpress.com/2011/02/image21.jpg"><br />
<img title="image2" src="http://sqlhelp.files.wordpress.com/2011/02/image21.jpg?w=169&#038;h=181" alt="" width="169" height="181" /></a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><code>IF  OBJECT_ID('tempdb..#LoanCustomer') IS NOT NULL<br />
DROP TABLE  #LoanCustomer</code></p>
<p><code><br />
CREATE TABLE #LoanCustomer (<br />
CustomerId INT,<br />
LoanId  INT,<br />
Amount MONEY<br />
)<br />
</code><br />
<code><br />
INSERT #LoanCustomer<br />
SELECT 1, 1,  500<br />
INSERT #LoanCustomer<br />
SELECT 2, 1, 5300<br />
INSERT  #LoanCustomer<br />
SELECT 3, 3, 1500<br />
INSERT #LoanCustomer<br />
SELECT 2, 1,  2500<br />
INSERT #LoanCustomer<br />
SELECT 1, 6, 5500<br />
INSERT  #LoanCustomer<br />
SELECT 2, 4, 1100<br />
INSERT #LoanCustomer<br />
SELECT 2, 3,  3200<br />
INSERT #LoanCustomer<br />
SELECT 2, 3, 3200<br />
</code></p>
<p><code>--Select * from  #LoanCustomer</code></p>
<p><a href="http://sqlhelp.files.wordpress.com/2011/02/image1.jpg"><br />
<img title="image1" src="http://sqlhelp.files.wordpress.com/2011/02/image1.jpg?w=253&#038;h=217" alt="" width="253" height="217" /></a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong>Combine Result of three table from PIVOT Query:</strong></p>
<p><code><br />
DECLARE<br />
@sql  VARCHAR(MAX)<br />
,@LoanType VARCHAR(MAX)</code><br />
<code><br />
SELECT<br />
@LoanType =  ISNULL(@LoanType + ', ', '') + '[' + LoanName + ']'<br />
FROM  (<br />
SELECT<br />
DISTINCT<br />
l.LoanName<br />
FROM #LoanCustomer lc<br />
INNER JOIN  #LoanType l ON lc.LoanId = l.LoanId<br />
) x<br />
</code></p>
<p><code><br />
SET @sql =  '<br />
SELECT<br />
CustomerName<br />
,' + @LoanType +<br />
Sample for Dynamic PIVOT</code></p>
<p><code><br />
FROM  (<br />
SELECT<br />
c.CustomerName,<br />
l.LoanName,<br />
lc.Amount<br />
FROM #LoanCustomer  lc<br />
INNER JOIN #customer c ON lc.CustomerId = c.CustomerId<br />
INNER JOIN  #LoanType l ON l.LoanId = lc.LoanId<br />
)  dataList<br />
PIVOT<br />
(<br />
SUM(Amount)<br />
FOR LoanName IN(' + @LoanType+ ')<br />
)  X '</code><br />
<code><br />
EXEC (@sql)<br />
</code></p>
<p><a href="http://sqlhelp.files.wordpress.com/2011/02/image21.jpg"></a><a href="http://sqlhelp.files.wordpress.com/2011/02/image31.jpg"></a><a href="http://sqlhelp.files.wordpress.com/2011/02/result1.jpg"></a></p>
<p><a href="http://sqlhelp.files.wordpress.com/2011/02/result1.jpg"><img class="alignnone size-medium wp-image-472" title="result" src="http://sqlhelp.files.wordpress.com/2011/02/result1.jpg?w=300&#038;h=126" alt="" width="300" height="126" /></a></p>
<p><a href="http://sqlhelp.files.wordpress.com/2011/02/result1.jpg"><br />
</a><a href="http://sqlhelp.files.wordpress.com/2011/02/all.jpg"><img class="alignnone size-medium wp-image-477" title="all" src="http://sqlhelp.files.wordpress.com/2011/02/all.jpg?w=300&#038;h=194" alt="" width="300" height="194" /></a></p>
<p>&nbsp;</p>
<p><strong>This Script is Prepared by Netra Prasad Acharya (MSSQL Developer)</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/465/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=465&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2011/02/14/dynamic-pivot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>

		<media:content url="http://sqlhelp.files.wordpress.com/2011/02/image31.jpg" medium="image">
			<media:title type="html">image3</media:title>
		</media:content>

		<media:content url="http://sqlhelp.files.wordpress.com/2011/02/image21.jpg" medium="image">
			<media:title type="html">image2</media:title>
		</media:content>

		<media:content url="http://sqlhelp.files.wordpress.com/2011/02/image1.jpg" medium="image">
			<media:title type="html">image1</media:title>
		</media:content>

		<media:content url="http://sqlhelp.files.wordpress.com/2011/02/result1.jpg?w=300" medium="image">
			<media:title type="html">result</media:title>
		</media:content>

		<media:content url="http://sqlhelp.files.wordpress.com/2011/02/all.jpg?w=300" medium="image">
			<media:title type="html">all</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL Hash Algorithms</title>
		<link>http://sqlhelp.wordpress.com/2010/12/21/hash-algorithms/</link>
		<comments>http://sqlhelp.wordpress.com/2010/12/21/hash-algorithms/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 09:14:27 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Hash Algorithms]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[MSSQL encrypt]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=459</guid>
		<description><![CDATA[MSSQL Hash Algorithms: There are two forms of encryption algorithms: one-way and two-way. Two-way algorithms allow you to encrypt and decrypt data. One-way algorithms will only encrypt data without any ability to decrypt. A hash algorithm is the simplest way to encrypt data, however, once encrypted, you can&#8217;t decrypt the data. Your data remains secure, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=459&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4>MSSQL Hash Algorithms:</h4>
<p>There are two forms of  encryption algorithms: one-way and two-way. Two-way algorithms allow you to  encrypt and decrypt data. One-way algorithms will only encrypt data without any  ability to decrypt.</p>
<p>A hash algorithm is the simplest way  to encrypt data, however, once encrypted, you can&#8217;t decrypt the data. Your data  remains secure, ensuring that in order to &#8220;decrypt&#8221; the contents of a column you  would first have to know the original data value.</p>
<p><code>--Different hash algorithms produce different hash values<br />
DECLARE @TEST_VAL varchar(100)<br />
SELECT @TEST_VAL = 'SQL Server'<br />
SELECT HashBytes('MD5', @TEST_VAL)<br />
SELECT @TEST_VAL = 'SQL Server'<br />
SELECT HashBytes('SHA1', @TEST_VAL)<br />
GO</code></p>
<p><code>--Hash values are case sensitive<br />
DECLARE @TEST_VAL varchar(100)<br />
SELECT @TEST_VAL = 'sql'<br />
SELECT HashBytes('SHA1', @TEST_VAL)<br />
SELECT @TEST_VAL = 'SQL'<br />
SELECT HashBytes('SHA1', @TEST_VAL)<br />
GO</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/459/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=459&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/12/21/hash-algorithms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>SUBSTRING Function</title>
		<link>http://sqlhelp.wordpress.com/2010/12/02/substring-function/</link>
		<comments>http://sqlhelp.wordpress.com/2010/12/02/substring-function/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 09:42:25 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SUBSTRING Function]]></category>
		<category><![CDATA[CHARINDEX]]></category>
		<category><![CDATA[REPLACE Functions of MSSQL.]]></category>
		<category><![CDATA[See the Uses of SUBSTRING]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=454</guid>
		<description><![CDATA[See the Uses of SUBSTRING, CHARINDEX, REPLACE Functions in MSSQL. SELECT '3/6/2010' as OLD_FORMAT, charindex('/','3/6/2010',1) [FIRST/POSITION], charindex('/','3/6/2010',3) [2nd/POSITION], replace( SUBSTRING ('3/6/2010', charindex('/','3/6/2010',1), 2),'/','') as MM, replace(left('3/6/2010',2),'/','') as DD, right('3/6/2010',4) as YYYY, replace( SUBSTRING ('3/6/2010', charindex('/','3/6/2010',1), 2),'/','')+'/'+ replace(left('3/6/2010',2),'/','')+'/'+ right('3/6/2010',4) as NEW_FORMAT Example to convert date  dd/mm/yyyy to mm/dd/yyyy<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=454&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>See the Uses of SUBSTRING, CHARINDEX, REPLACE Functions in MSSQL.</p>
<p><code><br />
SELECT<br />
'3/6/2010' as OLD_FORMAT,<br />
charindex('/','3/6/2010',1) [FIRST/POSITION],<br />
charindex('/','3/6/2010',3)  [2nd/POSITION],<br />
replace( SUBSTRING ('3/6/2010', charindex('/','3/6/2010',1), 2),'/','') as MM,<br />
replace(left('3/6/2010',2),'/','') as DD,<br />
right('3/6/2010',4) as YYYY,</code></p>
<p><code>replace( SUBSTRING ('3/6/2010', charindex('/','3/6/2010',1), 2),'/','')+'/'+<br />
replace(left('3/6/2010',2),'/','')+'/'+<br />
right('3/6/2010',4) as NEW_FORMAT</code></p>
<p>Example to convert date  dd/mm/yyyy to mm/dd/yyyy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/454/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=454&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/12/02/substring-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Short Cut key and formatting</title>
		<link>http://sqlhelp.wordpress.com/2010/07/10/short-cut-key/</link>
		<comments>http://sqlhelp.wordpress.com/2010/07/10/short-cut-key/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 06:06:09 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Short Cut key]]></category>
		<category><![CDATA[MSSQL Management Studio]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=444</guid>
		<description><![CDATA[MSSQL Short Cut key for query Editors: Some easy short cut key for MSSQL Management studio or Query Editor: CTRL + f1 = sp_help CTRL + 1 = sp_who CTRL + 2 = sp_lock CTRL + R = Show/Hide Result Window CTRL + E = Execute the SQL statement CTRL + L = Execute with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=444&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>MSSQL Short Cut key for query Editors:<br />
</strong><br />
Some easy short cut key for MSSQL Management studio or Query Editor:<strong><br />
</strong></p>
<p>CTRL + f1 = sp_help<br />
CTRL + 1 = sp_who<br />
CTRL + 2 = sp_lock</p>
<p>CTRL + R = Show/Hide Result Window<br />
CTRL + E = Execute the SQL statement<br />
CTRL + L = Execute with Execuation plan<br />
CTRL + G = GOTO line number<br />
CTRL + F = find<br />
CTRL + H = find and replace</p>
<p>CTRL + SHIFT + U = Convert to Upper Case<br />
CTRL + SHIFT + L = Convert to Lower Case</p>
<p>If you want to change the style of your query text editor in MSSQL Management studio:</p>
<p>Go to the following menu:</p>
<p><em>TOOLS  ==&gt; OPTIONS == &gt; ENVIRONMENT == &gt; FONTS AND COLORS</em></p>
<p><em><a href="http://sqlhelp.files.wordpress.com/2010/07/formatting.png"><img class="alignnone size-medium wp-image-448" style="border:1px solid black;margin:2px;" title="formatting" src="http://sqlhelp.files.wordpress.com/2010/07/formatting.png?w=300&#038;h=173" alt="MSSQL Formatting Window" width="300" height="173" /></a></em></p>
<p><em> </em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/444/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/444/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/444/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=444&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/07/10/short-cut-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>

		<media:content url="http://sqlhelp.files.wordpress.com/2010/07/formatting.png?w=300" medium="image">
			<media:title type="html">formatting</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL Backup to Map Drive</title>
		<link>http://sqlhelp.wordpress.com/2010/06/20/mssql-backup-to-map-drive/</link>
		<comments>http://sqlhelp.wordpress.com/2010/06/20/mssql-backup-to-map-drive/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 13:44:56 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MSSQL Backup to Map Drive]]></category>
		<category><![CDATA[Backup to network drive]]></category>
		<category><![CDATA[Login to network PC]]></category>
		<category><![CDATA[MSSQL Backup]]></category>
		<category><![CDATA[MSSQL help]]></category>
		<category><![CDATA[MSSQL tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=434</guid>
		<description><![CDATA[MSSQL Backup to Map Drive: if you want to backup a SQL Server database to a mapped drive use the following script 1) First it will create Map Drive in Local PC 2) Backup the Database. 3) Delete the Map Drive, so that next time the same script can use again. EXEC master..xp_cmdshell 'net use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=434&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>MSSQL Backup to Map Drive:</strong></p>
<p>if you want to backup a SQL Server database to a mapped drive use the following script<br />
1) First it will create Map Drive in Local PC<br />
2) Backup the Database.<br />
3) Delete the Map Drive, so that next time the same script can use again.</p>
<p><code>EXEC master..xp_cmdshell 'net use z: "\\192.168.1.93\share" password /user:user1'<br />
GO</code></p>
<p><code>BACKUP DATABASE DB1<br />
to disk='z:\db1.bak' with init<br />
GO<br />
</code><br />
<code>EXEC master..xp_cmdshell 'net use z: /delete'<br />
GO</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/434/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=434&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/06/20/mssql-backup-to-map-drive/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL MAX, MIN from the column data</title>
		<link>http://sqlhelp.wordpress.com/2010/05/12/mssql-max-min-from-the-column-data/</link>
		<comments>http://sqlhelp.wordpress.com/2010/05/12/mssql-max-min-from-the-column-data/#comments</comments>
		<pubDate>Wed, 12 May 2010 06:14:38 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MIN from the column data]]></category>
		<category><![CDATA[How to compare and find the MAX]]></category>
		<category><![CDATA[MAX User Fucntion]]></category>
		<category><![CDATA[MIN]]></category>
		<category><![CDATA[MSSQL MAX]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=406</guid>
		<description><![CDATA[How to compare and find the MAX, MIN from the column data? Some time we want to find the MAX, MIN form our own data or Colunm data On that case MSSQL dose not have system function to do it but here is the solution to do it. See the example to find Max value: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=406&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to compare and find the MAX, MIN from the column data?<br />
</strong>Some time we want to find the MAX, MIN form our own data or Colunm data On that case MSSQL dose not have system function to do it but here is the solution to do it.<strong> </strong></p>
<p><strong>See the example to find Max value:</strong><br />
<code><br />
-- select dbo.FuncGetMax(123,5,null,null,null)</code><br />
<code><br />
ALTER FUNCTION [dbo].[FuncGetMax] (@str float, @str1 float, @str2 float, @str3 float,@str4 float)<br />
RETURNS float<br />
BEGIN</code></p>
<p><code>Declare @result int</code></p>
<p><code>-- First compare</code><br />
<code>if @str &gt; @str1<br />
set @result=@str<br />
else<br />
set @result=@str1</code></p>
<p><code>-- 2nd compare</code><br />
<code>if @str2 is null OR @result &gt; @str2<br />
set @result=@result<br />
else<br />
set @result=@str2</code></p>
<p><code>-- 3rd compare</code><br />
<code>if @str3 is null OR @result &gt; @str3<br />
set @result=@result<br />
else<br />
set @result=@str3</code></p>
<p><code>-- 4th compare</code><br />
<code>if @str4 is null OR @result &gt; @str4<br />
set @result=@result<br />
else<br />
set @result=@str4</code></p>
<p><code>return @result</code><br />
<code><br />
end</code></p>
<p><strong>See the example to find MIN value:</strong></p>
<p><code><br />
-- select dbo.FuncGetMIN(123,5,null,null,null)</code></p>
<p><code>Alter FUNCTION [dbo].FuncGetMIN(@str float, @str1 float, @str2 float, @str3 float,@str4 float)<br />
RETURNS float<br />
BEGIN</code></p>
<p><code>Declare @result int</code></p>
<p><code>-- First compare</code><br />
<code>if @str &lt; @str1<br />
set @result=@str<br />
else<br />
set @result=@str1</code></p>
<p><code>-- 2nd compare</code><br />
<code>if @str2 is null OR @result &lt; @str2<br />
set @result=@result<br />
else<br />
set @result=@str2</code><br />
<code><br />
-- 3rd compare</code><br />
<code>if @str3 is null OR @result &lt; @str3<br />
set @result=@result<br />
else<br />
set @result=@str3</code></p>
<p><code>-- 4th compare</code><br />
<code>if @str4 is null OR @result &lt; @str4<br />
set @result=@result<br />
else<br />
set @result=@str4</code><br />
<code><br />
return @result</code></p>
<p><code>end</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=406&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/05/12/mssql-max-min-from-the-column-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL Cross-Tab Query</title>
		<link>http://sqlhelp.wordpress.com/2010/05/09/mssql-cross-tab-query/</link>
		<comments>http://sqlhelp.wordpress.com/2010/05/09/mssql-cross-tab-query/#comments</comments>
		<pubDate>Sun, 09 May 2010 11:09:04 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MSSQL Cross-Tab Query]]></category>
		<category><![CDATA[PIVOT Example]]></category>
		<category><![CDATA[Cross-Tab Query]]></category>
		<category><![CDATA[MSSQL Resources]]></category>
		<category><![CDATA[MSSQL Server help]]></category>
		<category><![CDATA[MSSQL tips]]></category>
		<category><![CDATA[MSSQL tricks]]></category>
		<category><![CDATA[PIVOT in MSSQL]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL script]]></category>
		<category><![CDATA[T-SQL PIVOT]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=420</guid>
		<description><![CDATA[Example Script for MSSQL Cross-Tab Query Create table #Table ( yearofJoining int, EmpId int, Deptid int ) GO insert into #Table select 1990,1,1 insert into #Table select 1991,2,2 insert into #Table select 1990,3,4 insert into #Table select 1991,4,2 insert into #Table select 1990,5,1 insert into #Table select 1990,6,3 insert into #Table select 1992,7,3 insert into [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=420&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Example Script for MSSQL Cross-Tab Query</strong></p>
<p><code>Create table #Table<br />
(<br />
yearofJoining int,<br />
EmpId int,<br />
Deptid int<br />
)<br />
GO</code></p>
<p><code><br />
insert into #Table select 1990,1,1<br />
insert into #Table select 1991,2,2<br />
insert into #Table select 1990,3,4<br />
insert into #Table select 1991,4,2<br />
insert into #Table select 1990,5,1<br />
insert into #Table select 1990,6,3<br />
insert into #Table select 1992,7,3<br />
insert into #Table select 1990,8,4<br />
insert into #Table select 1993,9,1<br />
insert into #Table select 1994,10,2<br />
insert into #Table select 1990,11,3<br />
insert into #Table select 1995,12,3<br />
insert into #Table select 1995,14,3<br />
insert into #Table select 1995,15,3<br />
insert into #Table select 1995,16,6<br />
GO</code></p>
<p><code>--Original Cross Tab query</code><br />
<code>select YearofJoining,<br />
count(case [DeptId] when 1 then 1 else null end) as [Department-1],<br />
count(case [DeptId] when 2 then 1 else null end) as [Department-2],<br />
count(case [DeptId] when 3 then 1 else null end) as [Department-3]<br />
from #Table where deptid in(1,2,3)<br />
group by Yearofjoining</code></p>
<p><strong>Out put:</strong></p>
<p><code>YearofJoining  Department-1  Department-2  Department-3<br />
-------------  ------------  ------------  ------------<br />
1990   2             0             2<br />
1991   0             2             0<br />
1992   0             0             1<br />
1993   1             0             0<br />
1994   0             1             0<br />
1995   0             0             3</code></p>
<p><strong>PIVOT Example:</strong></p>
<p><code><br />
SELECT YearofJoining, [1] as [Department-1],[2] as [Department-2],<br />
[3] as [Department-3] FROM<br />
(SELECT YearOfJoining,Deptid from #Table) p<br />
PIVOT<br />
( Count(DeptId) for DEPTID in ([1],[2],[3]))<br />
AS pvt<br />
ORDER BY Yearofjoining</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/420/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=420&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/05/09/mssql-cross-tab-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL Group by and Sum</title>
		<link>http://sqlhelp.wordpress.com/2010/04/09/mssql-group-by-and-sum/</link>
		<comments>http://sqlhelp.wordpress.com/2010/04/09/mssql-group-by-and-sum/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 10:53:33 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MSSQL Group by and Sum]]></category>
		<category><![CDATA[Group by and Sum in T-SQL]]></category>
		<category><![CDATA[MSQL tips]]></category>
		<category><![CDATA[SQL book]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL scripts]]></category>
		<category><![CDATA[Sum Example]]></category>
		<category><![CDATA[T-SQL Sum function]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=415</guid>
		<description><![CDATA[Here are some example for MSQL SUM function and GROUP BY: USE AdventureWorks; GO SELECT Color, SUM(ListPrice), SUM(StandardCost) FROM Production.Product WHERE Color IS NOT NULL AND ListPrice != 0.00 AND Name LIKE 'Mountain%' GROUP BY Color ORDER BY Color; GO Alternate way. USE AdventureWorks ; GO SELECT Color, ListPrice, StandardCost FROM Production.Product WHERE Color IS [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=415&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Here are some example for MSQL SUM function and GROUP BY:</strong></p>
<p><code><br />
USE AdventureWorks;<br />
GO<br />
SELECT Color, SUM(ListPrice), SUM(StandardCost)<br />
FROM Production.Product<br />
WHERE Color IS NOT NULL<br />
AND ListPrice != 0.00<br />
AND Name LIKE 'Mountain%'<br />
GROUP BY Color<br />
ORDER BY Color;<br />
GO<br />
</code></p>
<p><strong>Alternate way.</strong></p>
<p><code>USE AdventureWorks ;<br />
GO<br />
SELECT Color, ListPrice, StandardCost<br />
FROM Production.Product<br />
WHERE Color IS NOT NULL<br />
AND ListPrice != 0.00<br />
AND Name LIKE 'Mountain%'<br />
ORDER BY Color<br />
COMPUTE SUM(ListPrice), SUM(StandardCost) BY Color;<br />
GO</code></p>
<p><strong>Other Example:</strong></p>
<p><code>USE AdventureWorks;<br />
GO<br />
SELECT Color, SUM(ListPrice), SUM(StandardCost)<br />
FROM Production.Product<br />
GROUP BY Color<br />
ORDER BY Color;<br />
GO<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/415/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=415&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/04/09/mssql-group-by-and-sum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL Case</title>
		<link>http://sqlhelp.wordpress.com/2010/03/09/mssql-case/</link>
		<comments>http://sqlhelp.wordpress.com/2010/03/09/mssql-case/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 10:47:00 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MSSQL Case]]></category>
		<category><![CDATA[Case T-SQL]]></category>
		<category><![CDATA[Case when in SQL]]></category>
		<category><![CDATA[MSQL help]]></category>
		<category><![CDATA[MSSQL tips]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=412</guid>
		<description><![CDATA[Here are some example of MSSQL Cases: USE AdventureWorks; GO SELECT ProductNumber, Category = CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN 'Mountain' WHEN 'T' THEN 'Touring' WHEN 'S' THEN 'Other sale items' ELSE 'Not for sale' END, Name FROM Production.Product ORDER BY ProductNumber; GO Other way: USE AdventureWorks; GO SELECT ProductNumber, Name, 'Price [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=412&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Here are some example of MSSQL Cases:</strong></p>
<p><code>USE AdventureWorks;<br />
GO<br />
SELECT   ProductNumber, Category =<br />
CASE ProductLine<br />
WHEN 'R' THEN 'Road'<br />
WHEN 'M' THEN 'Mountain'<br />
WHEN 'T' THEN 'Touring'<br />
WHEN 'S' THEN 'Other sale items'<br />
ELSE 'Not for sale'<br />
END,<br />
Name<br />
FROM Production.Product<br />
ORDER BY ProductNumber;<br />
GO</code></p>
<p><strong>Other way:</strong></p>
<p><code>USE AdventureWorks;<br />
GO<br />
SELECT   ProductNumber, Name, 'Price Range' =<br />
CASE<br />
WHEN ListPrice =  0 THEN 'Mfg item - not for resale'<br />
WHEN ListPrice &lt; 50 THEN 'Under $50'          WHEN ListPrice &gt;= 50 and ListPrice &lt; 250 THEN 'Under $250'          WHEN ListPrice &gt;= 250 and ListPrice &lt; 1000 THEN 'Under $1000'<br />
ELSE 'Over $1000'<br />
END<br />
FROM Production.Product<br />
ORDER BY ProductNumber ;<br />
GO</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/412/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=412&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/03/09/mssql-case/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL EXISTS and IF EXISTS</title>
		<link>http://sqlhelp.wordpress.com/2010/03/01/mssql-exists/</link>
		<comments>http://sqlhelp.wordpress.com/2010/03/01/mssql-exists/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 11:20:52 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MSSQL EXISTS]]></category>
		<category><![CDATA[If Exists]]></category>
		<category><![CDATA[MSQL tricks]]></category>
		<category><![CDATA[MSSQL help]]></category>
		<category><![CDATA[MSSQL Resources]]></category>
		<category><![CDATA[MSSQL tips]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=425</guid>
		<description><![CDATA[Using NULL in a subquery to still return a result set: USE AdventureWorks ; GO SELECT DepartmentID, Name FROM HumanResources.Department WHERE EXISTS (SELECT NULL) ORDER BY Name ASC ; Comparing queries by using EXISTS and IN USE AdventureWorks ; GO SELECT a.FirstName, a.LastName FROM Person.Contact AS a WHERE EXISTS (SELECT * FROM HumanResources.Employee AS b [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=425&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Using NULL in a subquery to still return a result set:</strong></p>
<p><code>USE AdventureWorks ;<br />
GO<br />
SELECT DepartmentID, Name<br />
FROM HumanResources.Department<br />
WHERE EXISTS (SELECT NULL)<br />
ORDER BY Name ASC ;<br />
</code></p>
<p><strong>Comparing queries by using EXISTS and IN</strong></p>
<p><code>USE AdventureWorks ;<br />
GO<br />
SELECT a.FirstName, a.LastName<br />
FROM Person.Contact AS a<br />
WHERE EXISTS<br />
(SELECT *<br />
FROM HumanResources.Employee AS b<br />
WHERE a.ContactId = b.ContactID<br />
AND a.LastName = 'Johnson');<br />
GO</code></p>
<p><strong>Usage of IN :</strong></p>
<p><code>USE AdventureWorks ;<br />
GO<br />
SELECT a.FirstName, a.LastName<br />
FROM Person.Contact AS a<br />
WHERE a.LastName IN<br />
(SELECT a.LastName<br />
FROM HumanResources.Employee AS b<br />
WHERE a.ContactId = b.ContactID<br />
AND a.LastName = 'Johnson');<br />
GO</code></p>
<p><strong>Comparing queries by using EXISTS and = ANY</strong></p>
<p><code><br />
USE AdventureWorks ;<br />
GO<br />
SELECT DISTINCT s.Name<br />
FROM Sales.Store s<br />
WHERE EXISTS<br />
(SELECT *<br />
FROM Purchasing.Vendor v<br />
WHERE s.Name = v.Name) ;<br />
GO<br />
</code></p>
<p><strong>Usage of ANY:</strong></p>
<p><code>USE AdventureWorks ;<br />
GO<br />
SELECT DISTINCT s.Name<br />
FROM Sales.Store s<br />
WHERE s.Name = ANY<br />
(SELECT v.Name<br />
FROM Purchasing.Vendor v ) ;<br />
GO<br />
</code></p>
<p><strong>Comparing queries by using EXISTS and IN</strong></p>
<p><code>USE AdventureWorks;<br />
GO<br />
SELECT c.FirstName, c.LastName, e.Title<br />
FROM Person.Contact c JOIN HumanResources.Employee e<br />
ON e.ContactID = c.ContactID WHERE EXISTS<br />
(SELECT *<br />
FROM HumanResources.Department d<br />
WHERE e.DepartmentID = d.DepartmentID<br />
AND d.Name LIKE 'P%');<br />
GO<br />
</code></p>
<p><strong>Usage of IN :</strong></p>
<p><code>USE AdventureWorks;<br />
GO<br />
SELECT c.FirstName, c.LastName, e.Title<br />
FROM Person.Contact c JOIN HumanResources.Employee e<br />
ON e.ContactID = c.ContactID WHERE DepartmentID IN<br />
(SELECT DepartmentID<br />
FROM HumanResources.Department<br />
WHERE Name LIKE 'P%');<br />
GO</code></p>
<p><strong>Using NOT EXISTS</strong></p>
<p><code>USE AdventureWorks;<br />
GO<br />
SELECT c.FirstName, c.LastName, e.Title<br />
FROM Person.Contact c JOIN HumanResources.Employee e<br />
ON e.ContactID = c.ContactID WHERE NOT EXISTS<br />
(SELECT *<br />
FROM HumanResources.Department d<br />
WHERE e.DepartmentID = d.DepartmentID<br />
AND d.Name LIKE 'P%')<br />
ORDER BY LastName, FirstName<br />
GO</code></p>
<p><strong>Advance Usage of Exists</strong></p>
<p><code>If exists(<br />
SELECT id FROM Table1 where price &gt; = 1000<br />
)<br />
begin</code><br />
<code> SELECT  '&gt;= than 10000' as MSG<br />
print '&gt; than 10000'  -- OR you can print as out put<br />
return;</code><br />
<code><br />
end</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/425/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=425&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/03/01/mssql-exists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL Joins</title>
		<link>http://sqlhelp.wordpress.com/2010/02/09/mssql-joins/</link>
		<comments>http://sqlhelp.wordpress.com/2010/02/09/mssql-joins/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 10:38:52 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MSSQL Joins]]></category>
		<category><![CDATA[Inner join]]></category>
		<category><![CDATA[left join]]></category>
		<category><![CDATA[outer join]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=410</guid>
		<description><![CDATA[Here are some Example of SQL Joins --The basic JOIN statement -- JOIN: SELECT Customer.CustomerID, TransID, TransAmt FROM Customer JOIN Transaction ON Customer.CustomerID = Transaction.CustomerID; -- similar: SELECT Customer.CustomerID, TransID, TransAmt FROM Customer, Transaction; where Customer.CustomerID = Transaction.CustomerID; -- INNER JOIN SELECT CustomerName, TransDate FROM Customer INNER JOIN Transaction ON Customer.CustomerID = Transaction.CustomerID; -- LEFT [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=410&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Here are some Example of SQL Joins</strong></p>
<p><code><br />
--The basic JOIN statement<br />
-- JOIN:<br />
SELECT Customer.CustomerID, TransID, TransAmt<br />
FROM Customer JOIN Transaction<br />
ON Customer.CustomerID = Transaction.CustomerID;</code><br />
<code><br />
-- similar:<br />
SELECT Customer.CustomerID, TransID, TransAmt<br />
FROM Customer, Transaction;<br />
where Customer.CustomerID = Transaction.CustomerID;</code></p>
<p><code>-- INNER JOIN<br />
SELECT CustomerName, TransDate<br />
FROM Customer INNER JOIN Transaction<br />
ON Customer.CustomerID = Transaction.CustomerID;</code></p>
<p><code>-- LEFT OUTER JOIN<br />
SELECT CustomerName, TransDate, TransAmt<br />
FROM Customer LEFT OUTER JOIN Transaction<br />
ON Customer.CustomerID = Transaction.CustomerID;</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/410/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=410&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/02/09/mssql-joins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Temp Tables in MSSQL Database</title>
		<link>http://sqlhelp.wordpress.com/2010/01/28/temp-tables-in-mssql-database/</link>
		<comments>http://sqlhelp.wordpress.com/2010/01/28/temp-tables-in-mssql-database/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 08:23:51 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Temp Tables]]></category>
		<category><![CDATA[##table]]></category>
		<category><![CDATA[@tables]]></category>
		<category><![CDATA[Global Temporary Tables]]></category>
		<category><![CDATA[Local Temporary Tables]]></category>
		<category><![CDATA[MSSQL tables]]></category>
		<category><![CDATA[scopes of temp table]]></category>
		<category><![CDATA[tables variable]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=395</guid>
		<description><![CDATA[Different types of temp Tables in Exists in MSSQL Database: 1) # TABLE (Local Temporary Tables) This types of temp table is created and populated on disk, in the system database tempdb — with a session-specific identifier packed onto the name. CREATE TABLE #TABLE ( rowid INT, fname VARCHAR(200) ) 2) ##TABLES  (Global Temporary Tables) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=395&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Different types of temp Tables in Exists in MSSQL Database:</p>
<p><strong>1) </strong><strong># TABLE (Local Temporary Tables)</strong></p>
<p>This types of temp table is created and populated on disk, in the system database tempdb — with a session-specific identifier packed onto the name.</p>
<p><code>CREATE TABLE #TABLE<br />
(<br />
rowid INT,<br />
fname VARCHAR(200)<br />
)</code></p>
<p><strong>2) ##TABLES  (Global Temporary Tables</strong>)</p>
<p>This types of Global temporary tables operate much like local temporary tables; they are created in tempdb and cause less locking and logging than permanent tables. However, they are visible to all sessions, until the creating session goes out of scope (and the global ##temp table is no longer being referenced by other sessions)</p>
<p>If the session is running and other session try to create the Global Temp Table than second session will get a error.<br />
&#8220;There is already an object named ##TABLE in database. &#8220;</p>
<p><code>CREATE TABLE ##TABLE<br />
(<br />
rowid INT,<br />
fname VARCHAR(200)<br />
)</code></p>
<p><strong>3) @TABLES (</strong><strong>Table Variables )</strong></p>
<p>This types of table variable is created in memory, and so performs slightly better than #temp tables ( less locking and logging in a table variable). A table variable might still perform I/O to tempdb (which is where the performance issues of #temp tables make themselves apparent), though the documentation is not very explicit about this.</p>
<p><code>DECLARE @table TABLE<br />
(<br />
rowid INT,<br />
fname VARCHAR(200)<br />
)<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/395/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=395&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2010/01/28/temp-tables-in-mssql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>How to pass parameters dynamically</title>
		<link>http://sqlhelp.wordpress.com/2009/11/15/how-pass-parameters-dynamically/</link>
		<comments>http://sqlhelp.wordpress.com/2009/11/15/how-pass-parameters-dynamically/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 12:51:33 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Parameters dynamically]]></category>
		<category><![CDATA[Best way to call procedure]]></category>
		<category><![CDATA[COALESCE]]></category>
		<category><![CDATA[How pass parameters dynamically]]></category>
		<category><![CDATA[MSQL tips]]></category>
		<category><![CDATA[Optional parameter in SQL]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=387</guid>
		<description><![CDATA[How to pass parameters dynamically? MS-SQL has many features to call the procedure from other application and from SQL itself, See the example. Some time you need optional parameter in Procedure then assign null as default so that it will not ask you compulsory. CREATE PROCEDURE dbo.TESTPROCEDURE @param1 VARCHAR(32) = NULL, @param2 INT = NULL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=387&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to pass parameters dynamically</strong>?<br />
MS-SQL has many features to call the procedure from other application and from SQL itself, See the example.<br />
Some time you need optional parameter in Procedure then assign null as default so that it will not ask you compulsory.</p>
<p><code>CREATE PROCEDURE dbo.TESTPROCEDURE<br />
@param1 VARCHAR(32) = NULL,<br />
@param2 INT = NULL<br />
AS<br />
BEGIN<br />
SET NOCOUNT ON </code></p>
<p><code>SELECT Param1 = COALESCE<br />
(<br />
@param1,<br />
'@param1 was Blank'<br />
)</code></p>
<p><code>SELECT Param2 = COALESCE<br />
(<br />
RTRIM(@param2),<br />
'@param2 was Blank'<br />
)<br />
END<br />
GO</code></p>
<p><code>EXEC dbo.TESTPROCEDURE @param1='HELLO', @param2=1<br />
EXEC dbo.TESTPROCEDURE @param1='HELLO'<br />
EXEC dbo.TESTPROCEDURE @param2=1<br />
EXEC dbo.TESTPROCEDURE 'HELLO',1<br />
EXEC dbo.TESTPROCEDURE 'HELLO</code></p>
<blockquote><p>There are so many way to get the result from procedure, Choose any of them which you like.</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/387/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=387&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/11/15/how-pass-parameters-dynamically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Table Row in String</title>
		<link>http://sqlhelp.wordpress.com/2009/10/29/table-row-in-string/</link>
		<comments>http://sqlhelp.wordpress.com/2009/10/29/table-row-in-string/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 11:58:42 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Table Row in String]]></category>
		<category><![CDATA[COALESCE]]></category>
		<category><![CDATA[How to create a row data as string.]]></category>
		<category><![CDATA[MSSQL tisp]]></category>
		<category><![CDATA[MSSQL tricks]]></category>
		<category><![CDATA[Multiple value in single String]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[String creation]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=377</guid>
		<description><![CDATA[How to create the row data as string. If you have table row data and you need to show all the records in a single string, use the following query. DATA: -------------------- Name RAM SHYAM HARI RITA RESULT: --------------------- Name RAM,SHYAM,HARI,RITA Use the following query ------------------------------------ DECLARE @strList varchar(100) SELECT @strList = COALESCE(@strList + ', [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=377&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to create the row data as string.</strong></p>
<p>If you have table row data and you need to show all the records in a single string, use the following query.</p>
<pre><strong>DATA:</strong>
--------------------
<code>Name
RAM
SHYAM
HARI
RITA</code>

<strong>RESULT</strong>:
---------------------
<code>Name
RAM,SHYAM,HARI,RITA</code>

Use the following query
------------------------------------
<code>DECLARE @strList varchar(100)
SELECT @strList = COALESCE(@strList + ', ', '') +
 CAST(Name AS varchar(5))
FROM TABLE1

SELECT @strList</code></pre>
<p>There are complex example in internet but you can use this simple query to get this solutions. No need to use complex cursor to get such result.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/377/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=377&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/10/29/table-row-in-string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>How to parametrize OPENQUERY in MSSQL</title>
		<link>http://sqlhelp.wordpress.com/2009/10/07/how-to-parametrize-openquery-in-mssql/</link>
		<comments>http://sqlhelp.wordpress.com/2009/10/07/how-to-parametrize-openquery-in-mssql/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 07:17:19 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Parametrize OPENQUERY]]></category>
		<category><![CDATA[How to parametrize OPENQUERY in MSSQL]]></category>
		<category><![CDATA[Linked server]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL tricks]]></category>
		<category><![CDATA[OPENQUERY]]></category>
		<category><![CDATA[parametrize query]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=373</guid>
		<description><![CDATA[How to parametrize OPENQUERY in MSSQL: MSSQL has good feature of linked server between two different Database in same location or in remote location. OPENQUERY helps you to execute your query in Linked server (remote) . In linked server you can directly execute your query without OPENQUERY but the performance will be a issue. As [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=373&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to parametrize OPENQUERY in MSSQL:</strong></p>
<p>MSSQL has good feature of linked server between two different Database in same location or in remote location.<br />
OPENQUERY helps you to execute your query in Linked server (remote) .</p>
<p>In linked server you can directly execute your query without OPENQUERY but the performance will be a issue.</p>
<p>As per my experience OPENQUERY is best way to access the linked servers.</p>
<p><strong>If you want to pass your variable in OPENQUERY than it is so simple. Use the following way to pass your variable in OPENQUERY. </strong></p>
<p><strong><br />
</strong></p>
<p><code>DECLARE @strDate VARCHAR(10)<br />
DECLARE @strSql VARCHAR(8000)<br />
DECLARE @strLinked VARCHAR(8000)</code></p>
<p><code>SET @strDate= '2009-01-01'</code></p>
<p><code>SET @strSsql= 'SELECT * FROM TABLE1 WHERE TRN_DATE =' + '''' + '''' + @strDate+ '''' + ''''</code></p>
<p><code>SET @strLinked= 'SELECT * FROM OPENQUERY(MYLINKEDSERVER,' + '''' + @strSql+ '''' + ')'</code></p>
<p><code>--############ Print and see your script</code><br />
<code>PRINT @strLinked</code></p>
<p><code>--############ Final Execution</code><br />
<code>EXEC(@strLinked)</code></p>
<p><strong>As per MSDN:</strong></p>
<p>Executes the specified pass-through query on the specified linked server. This server is an OLE DB data source. OPENQUERY can be referenced in the FROM clause of a query as if it were a table name. OPENQUERY can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement. This is subject to the capabilities of the OLE DB provider. Although the query may return multiple result sets, OPENQUERY returns only the first one.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/373/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=373&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/10/07/how-to-parametrize-openquery-in-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>How to find date name in MSSQL</title>
		<link>http://sqlhelp.wordpress.com/2009/08/10/how-to-find-date-name/</link>
		<comments>http://sqlhelp.wordpress.com/2009/08/10/how-to-find-date-name/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 09:46:08 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[How to find Date Name]]></category>
		<category><![CDATA[datename]]></category>
		<category><![CDATA[dateName function in SQL]]></category>
		<category><![CDATA[dw]]></category>
		<category><![CDATA[getdate(0]]></category>
		<category><![CDATA[How to find Date Name in MSSQL]]></category>
		<category><![CDATA[how to return date name in SQL]]></category>
		<category><![CDATA[how to return dayname in SQL]]></category>
		<category><![CDATA[how to return weekday in SQL]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=367</guid>
		<description><![CDATA[How to find Date Name in MSSQL: if you want to return a weekday or date name of particular date then it is so simple in MSSQL. See the example: select DATENAME(dw , getDate()) This query returns today&#8217;s date name like Sunday, Monday etc. You can pass &#8220;dw&#8221; or &#8220;weekday&#8221; as a first parameter to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=367&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to find Date Name in MSSQL:</strong></p>
<p><strong></strong>if you want to return a weekday or date name of particular date then it is so simple in MSSQL.<br />
<strong><br />
See the example:</strong></p>
<p><code>select DATENAME(dw , getDate())<br />
</code><br />
This query returns today&#8217;s date name like Sunday, Monday etc.</p>
<p>You can pass &#8220;dw&#8221; or &#8220;weekday&#8221; as a first parameter to date name which specifies the part of date returned.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/367/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=367&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/08/10/how-to-find-date-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>How to delete the MSSQL transaction log.</title>
		<link>http://sqlhelp.wordpress.com/2009/08/09/how-to-delete-the-mssql-transaction-log/</link>
		<comments>http://sqlhelp.wordpress.com/2009/08/09/how-to-delete-the-mssql-transaction-log/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 13:34:35 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[How to delete the MSSQL transaction log.]]></category>
		<category><![CDATA[Advance query]]></category>
		<category><![CDATA[BACKUP LOG]]></category>
		<category><![CDATA[Database tricks]]></category>
		<category><![CDATA[DBA jobs]]></category>
		<category><![CDATA[DBCC]]></category>
		<category><![CDATA[DBCC SHRINKFILE]]></category>
		<category><![CDATA[How to check file size from query]]></category>
		<category><![CDATA[MSSQL LOG BACKUP]]></category>
		<category><![CDATA[step to clean your LOG size]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=361</guid>
		<description><![CDATA[How to delete the MSSQL transaction log. If your transaction log is big or too much large. it will utilize your space and other issue might be there, so you need to clean up the transaction log time to time. Follow the following steps and clean your LOG size. 1)  first take log backup BACKUP [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=361&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to delete the MSSQL transaction log.</strong></p>
<p>If your transaction log is big or too much large. it will utilize your space and other issue might be there, so you need to clean up the transaction log time to time. Follow the following steps and clean your LOG size.</p>
<p>1)  first take log backup</p>
<p><code>BACKUP LOG IMEKL TO DISK='d:\TEMP.bak' with init</code></p>
<p>2) Shrink your Database.</p>
<p><code><br />
USE TESTDB<br />
GO<br />
DBCC SHRINKFILE ('TESTDB_log', EMPTYFILE);<br />
GO<br />
</code></p>
<p><strong>From GUI mode: <em>Rclick  DB ==&gt; Task ==&gt; Shirinks ==&gt; Database ==&gt; specify size and press OK</em><br />
</strong></p>
<p>3) Now see your log and file size.</p>
<p><code><br />
SELECT name AS [File Name] , file_id, physical_name AS [Physical Name],<br />
size/128 AS [Total Size in MB],<br />
size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0<br />
AS [Available Space In MB]<br />
FROM sys.database_files;</code></p>
<p>MSDN:<br />
<span>You can reduce the default size of an empty file by using DBCC SHRINKFILE <em>target_size</em>. For example, if you create a 5-MB file and then shrink the file to 3 MB while the file is still empty, the default file size is set to 3 MB. This applies only to empty files that have never contained data.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/361/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=361&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/08/09/how-to-delete-the-mssql-transaction-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Display Line Numbers In SQL Queries</title>
		<link>http://sqlhelp.wordpress.com/2009/07/10/display-line-numbers-in-sql-queries/</link>
		<comments>http://sqlhelp.wordpress.com/2009/07/10/display-line-numbers-in-sql-queries/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 13:26:54 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Display Line Numbers]]></category>
		<category><![CDATA[Display Line Numbers In SQL Queries]]></category>
		<category><![CDATA[Line number in SQL]]></category>
		<category><![CDATA[SQL 2008 line number]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=356</guid>
		<description><![CDATA[Display Line Numbers In SQL Queries By default in SQL Query analyzer line numbers are not shown. Follow the steps below: GOTO:  Tools =&#62; Text Editor =&#62;All Languages =&#62; General =&#62;Line Number (Select this check box). Now when you open a “New Query” line numbers will appear.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=356&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Display Line Numbers In SQL Queries</strong></p>
<p>By default in SQL Query analyzer line numbers are not shown.</p>
<p>Follow the steps below:</p>
<p>GOTO:  Tools =&gt; Text Editor =&gt;All Languages =&gt; General =&gt;Line Number (Select this check box).</p>
<p>Now when you open a “New Query” line numbers will appear.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/356/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=356&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/07/10/display-line-numbers-in-sql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Saving change is not permitted</title>
		<link>http://sqlhelp.wordpress.com/2009/07/02/saving-change-is-not-permitted/</link>
		<comments>http://sqlhelp.wordpress.com/2009/07/02/saving-change-is-not-permitted/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 10:38:26 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Saving change is not permitted]]></category>
		<category><![CDATA[Permission issue to update table]]></category>
		<category><![CDATA[SQL 2008]]></category>
		<category><![CDATA[Sql 2008 Management Tools]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=348</guid>
		<description><![CDATA[Saving change is not permitted Some time if your setting changed by some one then you can not update table in MSSQL 2008. you will see the below error: &#8220;A table that can not be re-created or enabled the options prevent saving changes. Sql 2008 Management Tools: Can&#8217;t save changes that require Recreation of Database&#8221; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=348&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Saving change is not permitted</strong></p>
<p>Some time if your setting changed by some one then you can not update table in MSSQL 2008.<br />
you will see the below error:</p>
<blockquote><p>&#8220;A table that can not be re-created or enabled the options prevent saving changes.<br />
Sql 2008 Management Tools: Can&#8217;t save changes that require Recreation of Database&#8221;</p></blockquote>
<p>That time you need to update your setting.</p>
<p>The fix is:</p>
<p><strong>Go to Tools =&gt; Options =&gt; Designers =&gt;Tables and Designers and uncheck the <em>Prevent Saving Changes</em> <em>that require table re-creation </em>option:</strong></p>
<p>As it is, reverting back to the &#8216;old&#8217; behavior now doesn&#8217;t let you know that a table recreate is required either, so the behavior now is the same as was with the old tools. Here Microsoft added some useful functionality and then UI fails to expose it intelligently.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/348/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/348/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/348/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/348/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/348/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/348/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/348/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/348/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/348/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/348/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/348/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/348/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/348/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/348/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=348&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/07/02/saving-change-is-not-permitted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MERGE (Transact-SQL)</title>
		<link>http://sqlhelp.wordpress.com/2009/07/01/merge-transact-sql/</link>
		<comments>http://sqlhelp.wordpress.com/2009/07/01/merge-transact-sql/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 11:54:01 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MERGE (Transact-SQL 2008)]]></category>
		<category><![CDATA[How to use MERGE in SQL]]></category>
		<category><![CDATA[Multiple TSQL in SAME Query]]></category>
		<category><![CDATA[New SQL features]]></category>
		<category><![CDATA[Raghunath Bhandari]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=343</guid>
		<description><![CDATA[MERGE (Transact-SQL 2008) MERGE is new feature , it Performs insert, update, or delete operations on a target table based on the results of a join with a source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table. Examples [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=343&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div><strong>MERGE (Transact-SQL 2008)</strong></div>
<p><!--Content type: DocStudio. Transform: devdiv2mtps.xslt.--></p>
<p><span> </span></p>
<p>MERGE is new feature , it Performs insert, update, or delete operations on a target table based on the results of a join with a source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table.</p>
<p><strong>Examples </strong> <a id="sectionToggle2"></a></p>
<p><code>CREATE TABLE TABLE1<br />
(<br />
Monthid INTEGER,<br />
Month_Name VARCHAR(15)<br />
)<br />
GO<br />
INSERT INTO TABLE1<br />
VALUES(1,'JAN')<br />
INSERT INTO TABLE1<br />
VALUES(2,'FEB')<br />
INSERT INTO TABLE1<br />
VALUES(3,'MAR')<br />
INSERT INTO TABLE1<br />
VALUES(4,'APR')<br />
INSERT INTO TABLE1<br />
VALUES(5,'MAY')<br />
GO</code></p>
<p><code>CREATE TABLE TABLE2<br />
(<br />
Monthid INTEGER,<br />
Month_Name VARCHAR(15)<br />
)<br />
GO<br />
INSERT INTO TABLE2<br />
VALUES(1,'JAN')<br />
INSERT INTO TABLE2<br />
VALUES(6,'JUNE')<br />
INSERT INTO TABLE2<br />
VALUES(7,'JULY')</code><br />
<code><br />
select * from TABLE2<br />
select * from TABLE1</code></p>
<p><code>MERGE TABLE1 AS t1<br />
USING (SELECT Monthid,Month_Name FROM TABLE2) AS t2<br />
ON t1.Monthid = t2.Monthid<br />
WHEN MATCHED AND t1.Monthid &gt; 8 THEN DELETE<br />
WHEN MATCHED THEN UPDATE SET t1.Monthid = t2.Monthid<br />
WHEN NOT MATCHED THEN<br />
INSERT(Monthid,Month_Name)<br />
VALUES(Monthid,Month_Name);<br />
GO<br />
</code><br />
<strong>MSDN:<br />
Using MERGE to perform INSERT and UPDATE operations on a table in a single statement</strong></p>
<p>A common scenario is updating one or more columns in a table if a matching row exists, or inserting the data as a new row if a matching row does not exist. This is usually done by passing parameters to a stored procedure that contains the appropriate UPDATE and INSERT statements. With the MERGE statement, you can perform both tasks in a single statement. The following example shows a stored procedure that contains both an INSERT statement and an UPDATE statement. The procedure is then modified to perform the equivalent operations by using a single MERGE statement.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/343/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=343&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/07/01/merge-transact-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>CREATE TYPE TABLE (Transact-SQL 2008)</title>
		<link>http://sqlhelp.wordpress.com/2009/06/28/create-type-table-transact-sql-2008/</link>
		<comments>http://sqlhelp.wordpress.com/2009/06/28/create-type-table-transact-sql-2008/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 11:49:32 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[CREATE TYPE TABLE]]></category>
		<category><![CDATA[Author Raghunath Bhandari]]></category>
		<category><![CDATA[Create Type MyTable as TABLE]]></category>
		<category><![CDATA[how to use the Table UDT]]></category>
		<category><![CDATA[how to use Type Table in SQL 2008]]></category>
		<category><![CDATA[MS SQL new feature Create  type table]]></category>
		<category><![CDATA[New feature in SQL 2008]]></category>
		<category><![CDATA[SQL 2008]]></category>
		<category><![CDATA[Table UDT]]></category>
		<category><![CDATA[Table UDT as a parameter in SQL Stored Procedure.]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=338</guid>
		<description><![CDATA[CREATE TYPE TABLE (Transact-SQL 2008) Create TYPE  Table is new opotion in SQL2008. It is very easy to handle and good to use in TSQ. This is good as compare to TEMP Table. Here is the Example: Create Type MyTable as TABLE ( ID INT IDENTITY (1,1), NAME varchar(20), ADRES VARCHAR(200) ) DECLARE @T AS [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=338&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>CREATE TYPE TABLE (Transact-SQL 2008)</strong></p>
<p>Create TYPE  Table is new opotion in SQL2008. It is very easy to handle and good to use in TSQ.<br />
This is good as compare to TEMP Table.</p>
<p><strong>Here is the Example:</strong><br />
<code>Create Type MyTable as TABLE<br />
(<br />
ID INT IDENTITY (1,1),<br />
NAME varchar(20),<br />
ADRES VARCHAR(200)<br />
)<br />
</code><br />
<code>DECLARE @T AS MyTable;</code><br />
<code><br />
INSERT INTO @T( NAME, ADRES) VALUES( 'RAGHU', 'KTM' )<br />
INSERT INTO @T( NAME, ADRES) VALUES( 'RAGHU', 'KTM' )<br />
INSERT INTO @T( NAME, ADRES) VALUES( 'RAGHU', 'KTM' )<br />
INSERT INTO @T( NAME, ADRES) VALUES( 'RAGHU', 'KTM' )</code></p>
<p><code><br />
SELECT * FROM @T ;<br />
DROP TYPE MyTable;<br />
</code></p>
<p>Many a times, we need to utilize a single Stored Procedure to update multiple database tables with one-to-many relationships. In such occasions, we end up concatenating large strings, and inside the procedure, end up parsing the string to get records. With SQL Server 2008, it is very simple, and we no more need to write tons of lines of code to implement such requirements.</p>
<p><code>CREATE PROC dbo.sp_GetOrders<br />
(@T AS dbo.tbl_Order READONLY)<br />
AS<br />
SELECT O.OrderID, O.OrderDate, O.CustomerID<br />
FROM dbo.tbl_Order AS O JOIN @T AS T ON<br />
O.OrderID = T. OrderID<br />
ORDER BY T. RecordID;<br />
GO</code><br />
<code><br />
DECLARE @MyOrderIDs AS dbo.tbl_Order;<br />
INSERT INTO @MyOrderIDs(pos, orderid) VALUES(1, 10248)<br />
INSERT INTO @MyOrderIDs(pos, orderid) VALUES(2, 10250)<br />
INSERT INTO @MyOrderIDs(pos, orderid) VALUES(3, 10249);</code></p>
<p><code><br />
EXEC dbo.sp_GetOrders @T = @MyOrderIDs;<br />
</code></p>
<p>This example shows  how to use the <code>Table</code> UDT as a parameter in SQL Stored Procedure.<br />
Hope you enjoyed this feature. Happy Programming.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/338/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=338&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/06/28/create-type-table-transact-sql-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Find All SQL Server Instance Running in Local Network</title>
		<link>http://sqlhelp.wordpress.com/2009/04/27/find-all-sql-server-instance-running-in-local-network/</link>
		<comments>http://sqlhelp.wordpress.com/2009/04/27/find-all-sql-server-instance-running-in-local-network/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 09:50:53 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL Server Instance Running]]></category>
		<category><![CDATA[How to list all SQL Server Instance Running in Local Network:]]></category>
		<category><![CDATA[Instance Running]]></category>
		<category><![CDATA[MS SQL server]]></category>
		<category><![CDATA[MSSQL tips]]></category>
		<category><![CDATA[MSSQL tricks]]></category>
		<category><![CDATA[Raghunath Bhandari]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=332</guid>
		<description><![CDATA[How to list all SQL Server Instance Running in Local Network: Some time you need to see the List of other running SQL server on your network. It is so simple and easy to call from other application also. See the example: -- ######### Query EXEC master..xp_cmdshell 'osql -L' -- ############ Result NULL Servers: (local) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=332&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to list all SQL Server Instance Running in Local Network:</strong><br />
Some time you need to see the List of other running SQL server on your network. It is so simple and easy to call from other application also.</p>
<p>See the example:</p>
<pre>-- ######### Query
EXEC master..xp_cmdshell 'osql -L'

-- ############ Result

NULL
Servers:
    (local)
    MAIL_SERVER
    RAGHU
    RAGHU\SQLEXPRESS
    SERVER1
NULL</pre>
<p>If you want to get the same list from Command prompt then:</p>
<p>C:\&gt; osql -L</p>
<p>it will show you the same list.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/332/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=332&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/04/27/find-all-sql-server-instance-running-in-local-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>MSSQL Server cursors</title>
		<link>http://sqlhelp.wordpress.com/2009/04/06/mssql-server-cursors/</link>
		<comments>http://sqlhelp.wordpress.com/2009/04/06/mssql-server-cursors/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 09:57:43 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[MSSQL Server cursors]]></category>
		<category><![CDATA[Author Raghu]]></category>
		<category><![CDATA[cursors]]></category>
		<category><![CDATA[Example of cursors]]></category>
		<category><![CDATA[how to user cursors]]></category>
		<category><![CDATA[Select row by row]]></category>
		<category><![CDATA[SQL cursor]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=329</guid>
		<description><![CDATA[How to use MSSQL Server cursors? SQL Server cursors are database objects used to manipulate data in a set on a row-by-row basis. You can fetch cursor rows and perform operations on them in a loop just like using any looping mechanism found in any other programming language. Before you can use a cursor, you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=329&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to use MSSQL Server cursors?</strong><br />
SQL Server cursors are database objects used to manipulate data in a set on a row-by-row basis. You can fetch cursor rows and perform operations on them in a loop just like using any looping mechanism found in any other programming language. Before you can use a cursor, you need to declare it.</p>
<p><strong>Example:</strong></p>
<pre><code>declare @row as varchar(20)</code>
DECLARE cur1 CURSOR FOR

SELECT rowid FROM Table1</pre>
<pre>OPEN cur1</pre>
<pre>FETCH NEXT FROM cur1 INTO @row
WHILE @@FETCH_STATUS = 0
BEGIN</pre>
<pre>    SELECT * FROM Table1 WHERE rowid = @row</pre>
<pre>    FETCH NEXT FROM cur1 INTO @row</pre>
<pre>END
CLOSE cur1
DEALLOCATE cur1</pre>
<p><strong>DECLARE CURSOR</strong></p>
<p>The DECLARE CURSOR command defines the attributes of a Transact-SQL server cursor, such as its scrolling behavior and the query used to build the result set on which the cursor operates. DECLARE CURSOR accepts both a syntax based on the SQL-92 standard and a syntax using a set of Transact-SQL extensions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/329/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=329&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/04/06/mssql-server-cursors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Password Encryption and Decrypt</title>
		<link>http://sqlhelp.wordpress.com/2009/04/01/password-encryption-and-decrypt/</link>
		<comments>http://sqlhelp.wordpress.com/2009/04/01/password-encryption-and-decrypt/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 06:15:26 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Encrypt Password and Compare]]></category>
		<category><![CDATA[Easy way to check Password]]></category>
		<category><![CDATA[Insert encrypted value to a table]]></category>
		<category><![CDATA[MS SQL Password compare]]></category>
		<category><![CDATA[MSSQL builtin encrypt function]]></category>
		<category><![CDATA[MSSQL Encryption]]></category>
		<category><![CDATA[One way encryption]]></category>
		<category><![CDATA[Password encrypt function]]></category>
		<category><![CDATA[pwdcompare]]></category>
		<category><![CDATA[pwdencrypt]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=325</guid>
		<description><![CDATA[How to Encrypt Password and compare? MS SQL has its own built in function to Encrypt password or secure text and compare it. This is very simple see the Example: &#8212;1 , Create a Table to insert. Create table tempPassTable ( id int, pwd varbinary(200) ) &#8212;2, Insert encrypted value to a table. insert into [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=325&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to Encrypt Password and compare?</strong></p>
<p>MS SQL has its own built in function to Encrypt password or secure text and compare it. This is very simple see the Example:</p>
<p><strong>&#8212;1 , Create a Table to insert.</strong></p>
<pre>Create table tempPassTable
(
id int,
pwd varbinary(200)
)</pre>
<p><strong>&#8212;2, Insert encrypted value to a table.<br />
</strong></p>
<pre>insert into tempPassTable(id,pwd)
select 1, pwdencrypt('abcd')</pre>
<p><strong>&#8212;3, Compare encrypted value and user input value.<br />
</strong></p>
<pre>
if (select pwdcompare('abcd',pwd,0) from tempPassTable)=0
select 'Invalid Password'
else
select 'Valid Password'</pre>
<pre></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=325&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/04/01/password-encryption-and-decrypt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>TSQL Delete on join</title>
		<link>http://sqlhelp.wordpress.com/2009/02/27/tsql-delete-on-join/</link>
		<comments>http://sqlhelp.wordpress.com/2009/02/27/tsql-delete-on-join/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 09:08:25 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[TSQL Delete on join]]></category>
		<category><![CDATA[Delete statement on join]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[MS SQL delete on join]]></category>
		<category><![CDATA[SQL Delete on Join]]></category>
		<category><![CDATA[subquery delete]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=318</guid>
		<description><![CDATA[Delete statement on join: Some time you need to delete a table on join. This example will help you to run delete statement on sql join. Example: DELETE table1 FROM table1 t1 JOIN table2 t2 ON t1.IDCOL=t2.IDCOL This T-SQL is checking TABLE2, If records exists then delete TABLE1. Weather IDCOL is already there in TABLE2 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=318&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Delete statement on join:</strong></p>
<p>Some time you need to delete a table on join.<br />
This example will help you to run delete statement on sql join.</p>
<p><strong>Example:</strong></p>
<p><code>DELETE table1<br />
FROM </code><code>table1 </code><code> t1<br />
JOIN </code><code>table2 </code><code>t2 ON t1.IDCOL=t2.</code><code>IDCOL</code></p>
<p>This T-SQL is checking TABLE2, If records exists then delete TABLE1. Weather IDCOL is already there in TABLE2 or not?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/318/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=318&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/02/27/tsql-delete-on-join/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>How to find hard disk serial number ?</title>
		<link>http://sqlhelp.wordpress.com/2009/01/24/how-to-find-hard-disk-serial-number/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/24/how-to-find-hard-disk-serial-number/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 07:44:39 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Hard drive Serial Number]]></category>
		<category><![CDATA[Computer unique number]]></category>
		<category><![CDATA[Get Computer unique number form VB6]]></category>
		<category><![CDATA[get drive serial number]]></category>
		<category><![CDATA[getdrive serial number]]></category>
		<category><![CDATA[Hard disk serial number]]></category>
		<category><![CDATA[How to find Harddisk SerialNumber]]></category>
		<category><![CDATA[software security]]></category>
		<category><![CDATA[VB tips]]></category>
		<category><![CDATA[VB Tricks]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Visual basic code]]></category>
		<category><![CDATA[Visual Basic Tips]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=302</guid>
		<description><![CDATA[How to find hard disk serial number ? If you want to get the hard drive serial number or computer unique number then use this function. This is Visual Basic 6.0 Code to Get the Computer Hard Drive Serial Number. &#8216;Computer Unique No or hard drive serial number From Visual Basic Private Declare Function GetVolumeInformation [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=302&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to find hard disk serial number ?</strong></p>
<p>If you want to get the  hard drive serial number or computer unique number then use this function.<br />
This is Visual Basic 6.0 Code to Get the Computer Hard Drive Serial Number.</p>
<p>&#8216;Computer Unique No or hard drive serial number From Visual Basic</p>
<pre>Private Declare Function GetVolumeInformation _
Lib "kernel32.dll" _
Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Integer, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long</pre>
<p><strong>This Function will return serial number of a Drive</strong></p>
<pre>Public Function GetSerialNumber(DriveLetter As String) As String
Dim SerialNum As Long
Dim VolNameBuf As String
Dim FileSysNameBuf As String

Select Case Len(DriveLetter)
Case 1
If DriveLetter Like "[a-z]" Then
DriveLetter = Left$(DriveLetter, 1) &amp; ":\"
Else
GetSerialNumber = "Error - Bad drive designation"
End If
Case 2
If LCase(DriveLetter) Like "[a-z]:" Then
DriveLetter = DriveLetter &amp; "\"
Else
GetSerialNumber = "Error - Bad drive designation"
End If
Case 3
If LCase(DriveLetter) Like "[!a-z]:\" Then
GetSerialNumber = "Error - Bad drive designation"
End If
Case Else
GetSerialNumber = "Error - Bad drive designation"
End Select
If Len(GetSerialNumber) = 0 Then
VolNameBuf = String$(255, Chr$(0))
FileSysNameBuf = String$(255, Chr$(0))
GetVolumeInformation DriveLetter, VolNameBuf, _
Len(VolNameBuf), SerialNum, 0, 0, _
FileSysNameBuf, Len(FileSysNameBuf)
GetSerialNumber = Right$("00000000" &amp; Hex$(SerialNum), <img src='http://s0.wp.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />
End If
End Function</pre>
<blockquote><p>This is good for security purpose. some time if you want to run your EXE file on some computer only then this is the best way.</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=302&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/24/how-to-find-hard-disk-serial-number/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Send SMS using AT command</title>
		<link>http://sqlhelp.wordpress.com/2009/01/24/send-sms-using-at-command/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/24/send-sms-using-at-command/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 06:47:38 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Send SMS using AT command]]></category>
		<category><![CDATA[1]]></category>
		<category><![CDATA[8]]></category>
		<category><![CDATA[AT command]]></category>
		<category><![CDATA[AT command to send sms]]></category>
		<category><![CDATA[AT Commands]]></category>
		<category><![CDATA[AT+CMGF=1]]></category>
		<category><![CDATA[AT+CMGR]]></category>
		<category><![CDATA[GSM modem]]></category>
		<category><![CDATA[How to send SMS using AT commands]]></category>
		<category><![CDATA[MSComm1]]></category>
		<category><![CDATA[MSComm1.PortOpen = True]]></category>
		<category><![CDATA[MSComm1.Settings = "9600]]></category>
		<category><![CDATA[N]]></category>
		<category><![CDATA[send SMS]]></category>
		<category><![CDATA[SMS from GSM modem]]></category>
		<category><![CDATA[Use MScomm library]]></category>
		<category><![CDATA[VB code to send sms]]></category>
		<category><![CDATA[VB Tricks and Tips]]></category>
		<category><![CDATA[VB6 code to send sms]]></category>
		<category><![CDATA[Visual basic code to send sms]]></category>
		<category><![CDATA[Visual Basic Tips]]></category>
		<category><![CDATA[Visual Basic Tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=292</guid>
		<description><![CDATA[Send SMS using GSM modem from your computer. This Example shows you to use AT command to handle the GSM modem. Try this to send SMS using this example. 1- Insert a form in VB project 2- Insert textbox (txtMsg,txtDestinationNumber) 3- Insert command button (Command1) 4- Insert a MSComm1 5- Connect your mobile phone in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=292&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Send SMS using GSM modem from your computer. This Example shows you to use AT command to handle the GSM modem.<br />
<strong>Try this to send SMS using this example.</strong></p>
<p>1- Insert a form in VB project<br />
2- Insert textbox (txtMsg,txtDestinationNumber)<br />
3- Insert command button (Command1)<br />
4- Insert a MSComm1<br />
5- Connect your mobile phone in computer with datacable</p>
<pre>Private Sub Command1_Click()
Call SENDSMS
End Sub

Sub SENDSMS()
On Error GoTo Errr:
If MsgBox("Are you sure to send SMS Message", vbYesNo) = vbNo Then
    Exit Sub
End If</pre>
<pre>' Set up the communications port
MSComm1.CommPort = 5 ' Com Port 5</pre>
<pre>' Set for 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = "AT" &amp; Chr$(13)</pre>
<pre>' Set up the phone for a text message
MSComm1.Output = "AT+CMGF=1" &amp; Chr$(13)
MSComm1.Output = "AT+CMGS= " &amp; Chr(34) &amp; txtDestinationNumber.Text &amp; Chr(34) &amp; Chr$(13) &amp; Chr(10)
MSComm1.Output = txtMsg.Text &amp; Chr$(26)
MSComm1.PortOpen = False
MsgBox "Message Sent successfully"
Exit Sub</pre>
<pre>Errr:</pre>
<pre>MsgBox Err.Description &amp; Err.Number, vbExclamation

End Sub</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/292/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=292&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/24/send-sms-using-at-command/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>NULLIF (Transact-SQL)</title>
		<link>http://sqlhelp.wordpress.com/2009/01/23/nullif-transact-sql/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/23/nullif-transact-sql/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 11:32:39 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[NULLIF (Transact-SQL)]]></category>
		<category><![CDATA[difference between nullif and case]]></category>
		<category><![CDATA[MS SQL tricks]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[use of nullif]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=284</guid>
		<description><![CDATA[How to use NULLIF (Transact-SQL) NULLIF will Return a null value if the two specified expressions are equal. If you want to compare to fields and then this will work for you like : Run these examples and you can see how to use it on your way. Select NULLIF('aa','aa') Select isnull( NULLIF('aa','aa'),'right') MSDN is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=284&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>How to use NULLIF (Transact-SQL)</strong></p>
<p>NULLIF will Return a null value if the two specified expressions are equal. If you want to compare to fields and then this will work for you like :</p>
<p>Run these examples and you can see how to use it on your way.<br />
<code>Select NULLIF('aa','aa')<br />
Select isnull( NULLIF('aa','aa'),'right')</code></p>
<h3 class="subHeading">MSDN is comparing NULLIF and CASE</h3>
<div class="subSection">
<p>To show the similarity between <code>NULLIF</code> and <code>CASE</code>, the following queries evaluate whether the values in the <code>MakeFlag</code> and <code>FinishedGoodsFlag</code> columns are the same. The first query uses <code>NULLIF</code>. The second query uses the <code>CASE</code> expression.</p>
<p><code><br />
USE AdventureWorks;<br />
GO<br />
SELECT ProductID, MakeFlag, FinishedGoodsFlag,<br />
NULLIF(MakeFlag,FinishedGoodsFlag)AS 'Null if Equal'<br />
FROM Production.Product<br />
WHERE ProductID &lt; 10;<br />
GO</code></p>
<pre>SELECT ProductID, MakeFlag, FinishedGoodsFlag,'Null if Equal' =
CASE
WHEN MakeFlag = FinishedGoodsFlag THEN NULL
ELSE MakeFlag
END
FROM Production.Product
WHERE ProductID &lt; 10;
GO</pre>
<p>So NULLIF and ISNULL functions can help you on different way.</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/284/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=284&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/23/nullif-transact-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Format money/decimal with commas</title>
		<link>http://sqlhelp.wordpress.com/2009/01/14/format-moneydecimal-with-commas/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/14/format-moneydecimal-with-commas/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 09:04:20 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL Formating]]></category>
		<category><![CDATA[CONVERT function]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL format money/decimal with commas]]></category>
		<category><![CDATA[SQL formatting]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=245</guid>
		<description><![CDATA[SQL format money/decimal with commas: Sometimes you want to have your money fields properly formatted with commas like this: 13,243,543.57 You can use the CONVERT function and give a value between 0 and 2 to the style and the format will be displayed based on that Below is an example: DECLARE @v MONEY SELECT @v [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=245&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:small;"><strong>SQL format money/decimal with commas: </strong></span></p>
<p><span>Sometimes you want to have your money fields properly formatted with commas like this: 13,243,543.57<br />
You can use the CONVERT function and give a value between 0 and 2 to the style and the format will be displayed based on that</span></p>
<p><strong>Below is an example:</strong></p>
<pre><span>DECLARE @v MONEY
SELECT @v = 1322323.6666</span>

<span>SELECT CONVERT(VARCHAR,@v,0)  --1322323.67
Rounded but no formatting</span>

<span>SELECT CONVERT(VARCHAR,@v,1)    --1,322,323.67
Formatted with commas

SELECT CONVERT(VARCHAR,@v,2)    --1322323.6666
No formatting
</span></pre>
<p><strong><span>If you have a decimal field it doesn&#8217;t work with the convert function<br />
The work around is to convert it to money:</span></strong></p>
<pre><span>DECLARE @v2 DECIMAL (36,10)
SELECT @v2 = 13243543.56565656

SELECT CONVERT(VARCHAR,CONVERT(MONEY,@v2),1) --13,243,543.57
Formatted with commas</span></pre>
<p><span><br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/245/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=245&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/14/format-moneydecimal-with-commas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Difference with (nolock) vs (nolock) as a SQL Table Hint</title>
		<link>http://sqlhelp.wordpress.com/2009/01/14/difference-with-nolock-vs-nolock-as-a-sql-table-hint/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/14/difference-with-nolock-vs-nolock-as-a-sql-table-hint/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 06:07:20 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[with (nolock) vs (nolock)]]></category>
		<category><![CDATA[Difference with (nolock) vs (nolock)]]></category>
		<category><![CDATA[FASTFIRSTROW]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[NOEXPAND]]></category>
		<category><![CDATA[NOLOCK]]></category>
		<category><![CDATA[NOWAIT]]></category>
		<category><![CDATA[PAGLOCK]]></category>
		<category><![CDATA[READCOMMITTED]]></category>
		<category><![CDATA[READPAST]]></category>
		<category><![CDATA[READUNCOMMITTED]]></category>
		<category><![CDATA[REPEATABLEREAD]]></category>
		<category><![CDATA[ROWLOCK]]></category>
		<category><![CDATA[SERIALIZABLE]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<category><![CDATA[T-SQL best way]]></category>
		<category><![CDATA[Table Hints]]></category>
		<category><![CDATA[TABLOCK]]></category>
		<category><![CDATA[TABLOCKX]]></category>
		<category><![CDATA[UPDLOCK]]></category>
		<category><![CDATA[XLOCK]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=239</guid>
		<description><![CDATA[Difference with (nolock) vs (nolock) as a SQL Table Hint: select sum(amount) from reward_expired (nolock) difference was between using the table hint (nolock) and the table hint with (nolock). Look at MSDN under SQL 2005, &#8220;In SQL Server 2005, with some exceptions, table hints are supported in the FROM clause only when the hints are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=239&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Difference with (nolock) vs (nolock) as a SQL Table Hint:</strong></p>
<pre>select sum(amount) from reward_expired (nolock)</pre>
<p>difference was between using the table hint (nolock) and the table hint with (nolock).<br />
<strong>Look at MSDN under SQL 2005,</strong></p>
<p>&#8220;In SQL Server 2005, with some exceptions, table hints are supported in the FROM clause only when the hints are specified with the WITH keyword. Table hints also must be specified with parentheses.</p>
<p>The following table hints are allowed with and without the WITH keyword: NOLOCK, READUNCOMMITTED, UPDLOCK, REPEATABLEREAD, SERIALIZABLE, READCOMMITTED, FASTFIRSTROW, TABLOCK, TABLOCKX, PAGLOCK, ROWLOCK, NOWAIT, READPAST, XLOCK, and NOEXPAND. When these table hints are specified without the WITH keyword, the hints should be specified alone.&#8221;<br />
<strong><br />
Micorosft plan to remove the ability to use just (nolock), and to future proof all SQL, users should write all table hints using the with keyword.</strong></p>
<blockquote><p>Omitting the WITH keyword is a deprecated feature: This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/239/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=239&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/14/difference-with-nolock-vs-nolock-as-a-sql-table-hint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Table Hints (Transact-SQL)</title>
		<link>http://sqlhelp.wordpress.com/2009/01/13/table-hints-transact-sql/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/13/table-hints-transact-sql/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 12:20:46 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Table Hints]]></category>
		<category><![CDATA[and NOEXPAND]]></category>
		<category><![CDATA[FASTFIRSTROW]]></category>
		<category><![CDATA[MSSQL Table Hints]]></category>
		<category><![CDATA[NOLOCK]]></category>
		<category><![CDATA[NOWAIT]]></category>
		<category><![CDATA[PAGLOCK]]></category>
		<category><![CDATA[READCOMMITTED]]></category>
		<category><![CDATA[READPAST]]></category>
		<category><![CDATA[READUNCOMMITTED]]></category>
		<category><![CDATA[REPEATABLEREAD]]></category>
		<category><![CDATA[ROWLOCK]]></category>
		<category><![CDATA[SERIALIZABLE]]></category>
		<category><![CDATA[SQL Locks]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<category><![CDATA[Table Hints (Transact-SQL)]]></category>
		<category><![CDATA[TABLOCK]]></category>
		<category><![CDATA[TABLOCKX]]></category>
		<category><![CDATA[UPDLOCK]]></category>
		<category><![CDATA[XLOCK]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=236</guid>
		<description><![CDATA[Table Hints (Transact-SQL) Table hints override the default behavior of the query optimizer for the duration of the data manipulation language (DML) statement by specifying a locking method, one or more indexes, a query processing operation such as a table scan or index seek, or other options. WITH ( &#60;table_hint&#62; [ [ , ]...n ] [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=236&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Table Hints (Transact-SQL)</strong></p>
<p>Table hints override the default behavior of the query optimizer for the duration of the data manipulation language (DML) statement by specifying a locking method, one or more indexes, a query processing operation such as a table scan or index seek, or other options.</p>
<pre>WITH ( &lt;table_hint&gt; [ [ , ]...n ] )

&lt;table_hint&gt; ::=
[ NOEXPAND ] {
    INDEX ( index_value [ ,...n ] ) | INDEX = ( index_value )
  | FASTFIRSTROW
  | FORCESEEK
  | HOLDLOCK
  | NOLOCK
  | NOWAIT
  | PAGLOCK
  | READCOMMITTED
  | READCOMMITTEDLOCK
  | READPAST
  | READUNCOMMITTED
  | REPEATABLEREAD
  | ROWLOCK
  | SERIALIZABLE
  | TABLOCK
  | TABLOCKX
  | UPDLOCK
  | XLOCK
} 

&lt;table_hint_limited&gt; ::=
{
    KEEPIDENTITY
  | KEEPDEFAULTS
  | FASTFIRSTROW
  | HOLDLOCK
  | IGNORE_CONSTRAINTS
  | IGNORE_TRIGGERS
  | NOWAIT
  | PAGLOCK
  | READCOMMITTED
  | READCOMMITTEDLOCK
  | READPAST
  | REPEATABLEREAD
  | ROWLOCK
  | SERIALIZABLE
  | TABLOCK
  | TABLOCKX
  | UPDLOCK
  | XLOCK
}</pre>
<p>The following table hints are allowed with and without the WITH<br />
keyword: NOLOCK, READUNCOMMITTED, UPDLOCK, REPEATABLEREAD,<br />
SERIALIZABLE, READCOMMITTED, FASTFIRSTROW, TABLOCK, TABLOCKX, PAGLOCK,<br />
ROWLOCK, NOWAIT, READPAST, XLOCK, and NOEXPAND. When these table hints<br />
are specified without the WITH keyword, the hints should be specified<br />
alone.</p>
<p><strong>For example:</strong><br />
<code><br />
Select * FROM table1 (TABLOCK)</code></p>
<p><code>Select * FROM table1 WITH (TABLOCK, INDEX(myindex))</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=236&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/13/table-hints-transact-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Reducing SQL Server Deadlocks</title>
		<link>http://sqlhelp.wordpress.com/2009/01/13/reducing-sql-server-deadlocks/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/13/reducing-sql-server-deadlocks/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 11:00:18 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL Deadlocking]]></category>
		<category><![CDATA[MS SQL Deadlocks]]></category>
		<category><![CDATA[NOLOCK]]></category>
		<category><![CDATA[PAGLOCK]]></category>
		<category><![CDATA[ROWLOCK]]></category>
		<category><![CDATA[Solve Deadlocks]]></category>
		<category><![CDATA[SQL Best practices and tips]]></category>
		<category><![CDATA[SQL Deadlocking refers to the condition]]></category>
		<category><![CDATA[SQL Deadlocks]]></category>
		<category><![CDATA[SQL Locks]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=230</guid>
		<description><![CDATA[Deadlocking and SQL best practices: Deadlocking refers to the condition in which one resource is waiting on the action of a second, while that second action is waiting on the first. This is different from being blocked, or having to wait for a resource. Using the locks above, if a transaction had a shared lock, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=230&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Deadlocking and SQL best practices:</strong></p>
<p>Deadlocking refers to the condition in which one resource is waiting on the action of a second, while that second action is waiting on the first. This is different from being blocked, or having to wait for a resource. Using the locks above, if a transaction had a shared lock, then you issued a delete on those same records held by the first lock, you would not be deadlocked. Instead, you would be blocked. When the shared lock was released, your delete statement would complete. Blocking implies some performance hit, but the transaction will complete. It simply has to wait for something else to finish first. A deadlock on the other hand, means there is no way to finish. Your transaction is stuck in a loop with some other transaction. At this point, the database system will usually pick one transaction to be killed so the other can complete.</p>
<p><strong>Here are some tips on how to avoid deadlocking on your SQL Server:</strong></p>
<ul>
<li>Esure the database design is properly normalized.</li>
<li>Have the application access server objects in the same order each time.</li>
<li>During transactions, don&#8217;t allow any user input. Collect it before the transaction begins.</li>
<li>Avoid cursors.</li>
<li>Keep transactions as short as possible. One way to help accomplish this is to reduce the number of round trips between your application and SQL Server by using stored procedures or keeping transactions with a single batch. Another way of reducing the time a transaction takes to complete is to make sure you are not performing the same reads over and over again. If your application does need to read the same data more than once, cache it by storing it in a variable or an array, and then re-reading it from there, not from SQL Server.</li>
<li>Reduce lock time. Try to develop your application so that it grabs locks at the latest possible time, and then releases them at the very earliest time.</li>
<li>If appropriate, reduce lock escalation by using the ROWLOCK or PAGLOCK.</li>
<li>Consider using the NOLOCK hint to prevent locking if the data being locked is not modified often.</li>
<li>If appropriate, use as low of an isolation level as possible for the user connection running the transaction.</li>
<li>Consider using bound connections</li>
<li>Remember to SET NOCOUNT ON at the beginning of your SQL bataches, stored procedures, triggers to avoid network traffic. This will also reduct the chances of error on linked server.</li>
<li>Index should be created on highly selective columns, which are used in JOINS, WHERE and ORDER BY clause.</li>
<li>Use Column name in ORDER BY clause instead of numbers.</li>
<li>Do not use TEXT or NTEXT if possible. In SQL Server 2005 use VARCHAR(MAX) or NVARCHAR(MAX).</li>
<li>Do not use SELECT *, use proper column names to decrease network traffic and fewer locks on table.</li>
</ul>
<blockquote><p>
Use SQL Server Profiler to identify the cause of a deadlock. A deadlock occurs when there is a cyclic dependency between two or more threads, or processes, for some set of resources within SQL Server. Using SQL Server Profiler, you can create a trace that records, replays, and displays deadlock events for analysis.</p>
<p>To trace deadlock events, add the Deadlock graph event class to a trace. This event class populates the TextData data column in the trace with XML data about the process and objects that are involved in the deadlock. SQL Server Profiler can extract the XML document to a deadlock XML (.xdl) file which you can view later in SQL Server Management Studio. You can configure SQL Server Profiler to extract Deadlock graph events to a single file that contains all Deadlock graph events, or to separate files. This extraction can be done in any of the following ways:</p></blockquote>
<ul>
<li>At trace configuration time, using the Events Extraction Settings tab. Note that this tab does not appear until you select the Deadlock graph event on the Events Selection tab.</li>
<li>Using the Extract SQL Server Events option on the File menu.</li>
<li>Individual events can also be extracted and saved by right-clicking a specific event and choosing Extract Event Data.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=230&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/13/reducing-sql-server-deadlocks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>HOW TO USE  ROLLUP and CUBE</title>
		<link>http://sqlhelp.wordpress.com/2009/01/07/how-to-use-rollup/</link>
		<comments>http://sqlhelp.wordpress.com/2009/01/07/how-to-use-rollup/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 08:42:51 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL rollup/cube]]></category>
		<category><![CDATA[How to use Rollup in SQL]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[Query sum option]]></category>
		<category><![CDATA[Running total generate]]></category>
		<category><![CDATA[SQL cube]]></category>
		<category><![CDATA[SQL Rollup]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[The differences between CUBE and ROLLUP]]></category>
		<category><![CDATA[What is CUBE]]></category>
		<category><![CDATA[What is Rollup]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=224</guid>
		<description><![CDATA[HOW TO USE CUBE: The CUBE operator generates a result set that is a multidimensional cube. A multidimensional cube is an expansion of fact data, or data that records individual events. The expansion is based on columns that the user wants to analyze. These columns are called dimensions. The cube is a result set containing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=224&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>HOW TO USE  CUBE:</strong></p>
<p>The CUBE operator generates a result set that is a multidimensional cube. A multidimensional cube is an expansion of fact data, or data that records individual events. The expansion is based on columns that the user wants to analyze. These columns are called dimensions. The cube is a result set containing a cross tabulation of all the possible combinations of the dimensions.</p>
<p>The CUBE operator is specified in the GROUP BY clause of a SELECT statement. The select list contains the dimension columns and aggregate function expressions. The GROUP BY specifies the dimension columns and the keywords WITH CUBE. The result set contains all possible combinations of the values in the dimension columns, along with the aggregate values from the underlying rows that match that combination of dimension values.</p>
<p><strong>For example, a simple table Inventory contains:</strong></p>
<pre><code>Item                 Color                Quantity
-------------------- -------------------- --------------------------
Table                Blue                 124
Table                Red                  223
Chair                Blue                 101
Chair                Red                  210</code></pre>
<p>This query returns a result set that contains the Quantity subtotal for all possible combinations of Item and Color:</p>
<p><code>SELECT Item, Color, SUM(Quantity) AS QtySum<br />
FROM Inventory<br />
GROUP BY Item, Color WITH CUBE</code></p>
<p><strong>Here is the result set:</strong></p>
<pre><code>Item                 Color                QtySum
-------------------- -------------------- --------------------------
Chair                Blue                 101.00
Chair                Red                  210.00
Chair                (null)               311.00
Table                Blue                 124.00
Table                Red                  223.00
Table                (null)               347.00
(null)               (null)               658.00
(null)               Blue                 225.00
(null)               Red                  433.00</code></pre>
<p>The following rows from the result set are of special interest:</p>
<p>Chair                (null)               311.00</p>
<p>This row reports a subtotal for all rows having the value Chair in the Item dimension. The value NULL is returned for the Color dimension to show that aggregate reported by the row includes rows with any value of the Color dimension.</p>
<p><code>Table                (null)               347.00</code></p>
<p>This row is similar, but reports the subtotal for all rows having Table in the Item dimension.<br />
<code><br />
(null)               (null)               658.00</code></p>
<p>This row reports the grand total for the cube. Both the Item and Color dimensions have the value NULL showing that all values of both dimensions are summarized in the row.</p>
<p><code>(null)               Blue                 225.00<br />
(null)               Red                  433.00</code></p>
<p>These two rows report the subtotals for the Color dimension. Both have NULL in the Item dimension to show that the aggregate data came from rows having any value for the Item dimension.</p>
<p>Using GROUPING to Distinguish Null Values<br />
The null values generated by the CUBE operation present a problem: How can a NULL generated by the CUBE operation be distinguished from a NULL returned in the actual data? This is achieved using the GROUPING function. The GROUPING function returns 0, if the column value came from the fact data, and 1 if the column value is a NULL generated by the CUBE operation. In a CUBE operation, a generated NULL represents all values. The SELECT statement can be written to use the GROUPING function to substitute the string ALL in place of any generated NULL. Because a NULL from the fact data indicates the data value is unknown, the SELECT can also be coded to return the string UNKNOWN in place of any NULL from the fact data. For example:</p>
<p><code>SELECT CASE WHEN (GROUPING(Item) = 1) THEN 'ALL'<br />
ELSE ISNULL(Item, 'UNKNOWN')<br />
END AS Item,<br />
CASE WHEN (GROUPING(Color) = 1) THEN 'ALL'<br />
ELSE ISNULL(Color, 'UNKNOWN')<br />
END AS Color,<br />
SUM(Quantity) AS QtySum<br />
FROM Inventory<br />
GROUP BY Item, Color WITH CUBE</code></p>
<p>Multidimensional Cubes<br />
The CUBE operator can be used to generate n-dimensional cubes, or cubes with any number of dimensions. A single dimension cube can be used to generate a total, for example:</p>
<p><code>SELECT CASE WHEN (GROUPING(Item) = 1) THEN 'ALL'<br />
ELSE ISNULL(Item, 'UNKNOWN')<br />
END AS Item,<br />
SUM(Quantity) AS QtySum<br />
FROM Inventory<br />
GROUP BY Item WITH CUBE<br />
GO</code></p>
<p>This SELECT statement returns a result set showing both the subtotals for each value of Item and the grand total for all values of Item:</p>
<pre><code>Item                 QtySum
-------------------- --------------------------
Chair                311.00
Table                347.00
ALL                  658.00</code></pre>
<p>SELECT statements that contain a CUBE with many dimensions can generate large result sets, because these statements generate rows for all combinations of the values in all the dimensions. These large result sets may contain too much data to be easily read and understood. One solution to this problem is to put the SELECT statement into a view:<br />
<code><br />
CREATE VIEW InvCube AS<br />
SELECT CASE WHEN (GROUPING(Item) = 1) THEN 'ALL'<br />
ELSE ISNULL(Item, 'UNKNOWN')<br />
END AS Item,<br />
CASE WHEN (GROUPING(Color) = 1) THEN 'ALL'<br />
ELSE ISNULL(Color, 'UNKNOWN')<br />
END AS Color,<br />
SUM(Quantity) AS QtySum<br />
FROM Inventory<br />
GROUP BY Item, Color WITH CUBE</code></p>
<p>The view can then be used to query only the dimension values of interest:</p>
<p><code>SELECT *<br />
FROM InvCube<br />
WHERE Item = 'Chair'<br />
AND Color = 'ALL'</code></p>
<pre>Item                 Color                QtySum
-------------------- -------------------- --------------------------
Chair                ALL                  311.00</pre>
<p><strong>HOW TO USE  ROLLUP:</strong></p>
<p>The ROLLUP operator is useful in generating reports that contain subtotals and totals. The ROLLUP operator generates a result set that is similar to the result sets generated by the CUBE operator. For more information, see Summarizing Data Using CUBE.</p>
<p>The differences between CUBE and ROLLUP are:</p>
<p>CUBE generates a result set showing aggregates for all combinations of values in the selected columns.</p>
<p>ROLLUP generates a result set showing aggregates for a hierarchy of values in the selected columns.<br />
For example, a simple table Inventory contains:</p>
<pre><code>Item                 Color                Quantity</code>
<code>-------------------- -------------------- --------------------------</code>
<code>Table                Blue                 124</code>
<code>Table                Red                  223</code>
<code>Chair                Blue                 101</code>
<code>Chair                Red                  210</code></pre>
<p><strong>This query generates a subtotal report:</strong></p>
<p><code>SELECT CASE WHEN (GROUPING(Item) = 1) THEN 'ALL'<br />
ELSE ISNULL(Item, 'UNKNOWN')<br />
END AS Item,<br />
CASE WHEN (GROUPING(Color) = 1) THEN 'ALL'<br />
ELSE ISNULL(Color, 'UNKNOWN')<br />
END AS Color,<br />
SUM(Quantity) AS QtySum<br />
FROM Inventory<br />
GROUP BY Item, Color WITH ROLLUP</code></p>
<pre><code>Item                 Color                QtySum
-------------------- -------------------- --------------------------
Chair                Blue                 101.00
Chair                Red                  210.00
Chair                ALL                  311.00
Table                Blue                 124.00
Table                Red                  223.00
Table                ALL                  347.00
ALL                  ALL                  658.00</code></pre>
<pre>(7 row(s) affected)</pre>
<p>If the ROLLUP keyword in the query is changed to CUBE, the CUBE result set is the same, except these two additional rows are returned at the end:</p>
<p><code>ALL                  Blue                 225.00<br />
ALL                  Red                  433.00</code></p>
<p>The CUBE operation generated rows for possible combinations of values from both Item and Color. For example, not only does CUBE report all possible combinations of Color values combined with the Item value Chair (Red, Blue, and Red + Blue), it also reports all possible combinations of Item values combined with the Color value Red (Chair, Table, and Chair + Table).</p>
<p>For each value in the columns on the right in the GROUP BY clause, the ROLLUP operation does not report all possible combinations of values from the column (or columns) on the left. For example, ROLLUP does not report all the possible combinations of Item values for each Color value.</p>
<p>The result set of a ROLLUP operation has functionality similar to that returned by a COMPUTE BY; however, ROLLUP has these advantages:</p>
<p>ROLLUP returns a single result set; COMPUTE BY returns multiple result sets that increase the complexity of application code.</p>
<p>ROLLUP can be used in a server cursor; COMPUTE BY cannot.</p>
<p>The query optimizer can sometimes generate more efficient execution plans for ROLLUP than it can for COMPUTE BY.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=224&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2009/01/07/how-to-use-rollup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL running serial generating tips</title>
		<link>http://sqlhelp.wordpress.com/2008/12/31/sql-running-serial-generating-tips/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/31/sql-running-serial-generating-tips/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 07:48:41 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL ROW_NUMBER]]></category>
		<category><![CDATA[Generate Row number]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[ROW_NUMBER()]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL running serial]]></category>
		<category><![CDATA[SQL running serial generating]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<category><![CDATA[sqlhelp]]></category>
		<category><![CDATA[SQLtips]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=221</guid>
		<description><![CDATA[SQL running serial generating tips: Traditionally developers and Database administrators used temporary tables and co-related sub-queries to generate calculated row numbers in a query. Now SQL Server 2005 provides a function, which replaces all of the additional resources we used to generate row numbers. Returns the sequential number of a row within a partition of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=221&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>SQL running serial generating tips</strong>:</p>
<p><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Traditionally developers and Database administrators used temporary tables and co-related sub-queries to generate calculated row numbers in a query. Now SQL Server 2005 provides a function, which replaces all of the additional resources we used to generate row numbers.</span></span></p>
<blockquote><p>Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.</p></blockquote>
<p><strong>Example:</strong></p>
<p><code>select ROW_NUMBER() OVER(ORDER BY CLM1),* from Table1</code></p>
<p><strong>Remark: </strong></p>
<div id="ctl00_rs1_mainContentContainer_cpe52969_c" class="MTPS_CollapsibleSection" style="overflow:visible;display:block;height:auto;width:982.7px;">
<div class="MTPS_CollapsibleSection" style="display:block;"><a id="remarksToggle"></a>The ORDER BY clause determines the sequence in which the rows are assigned their unique<br />
ROW_NUMBER within a specified partition.</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/221/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=221&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/31/sql-running-serial-generating-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Enable remote connection SQL Server</title>
		<link>http://sqlhelp.wordpress.com/2008/12/26/enable-remote-connection-sql-server/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/26/enable-remote-connection-sql-server/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 11:50:30 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL remote connection]]></category>
		<category><![CDATA[An error has occurred while establishing a connection to the server]]></category>
		<category><![CDATA[connection SQL Server]]></category>
		<category><![CDATA[Enable remote connection SQL Server]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[problem in remote connection SQL Server]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=217</guid>
		<description><![CDATA[Error Description :: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 &#8211; Could not open a connection to SQL Server) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=217&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote>
<h3><strong>Error Description ::</strong></h3>
<p>An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 &#8211; Could not open a connection to SQL Server)</p></blockquote>
<h3>Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer Edition</h3>
<p>You must enable remote connections for each instance of SQL Server 2005 that you want to connect to from a remote computer. To do this, follow these steps:</p>
<ol>
<li>Click <strong class="uiterm">Start</strong>, point to <strong class="uiterm">Programs</strong>, point to <strong class="uiterm">Microsoft SQL Server 2005</strong>, point to <strong class="uiterm">Configuration Tools</strong>, and then click <strong class="uiterm">SQL Server Surface Area Configuration</strong>.</li>
<li>On the <strong class="uiterm">SQL Server 2005 Surface Area Configuration</strong> page, click <strong class="uiterm">Surface Area Configuration for Services and Connections</strong>.</li>
<li>On the <strong class="uiterm">Surface Area Configuration for Services and Connections</strong> page, expand <strong class="uiterm">Database Engine</strong>,  click <strong class="uiterm">Remote Connections</strong>, click <strong class="uiterm">Local and remote connections</strong>, click the appropriate protocol to enable for your environment, and then click <strong class="uiterm">Apply</strong>.<strong>Note</strong> Click <strong class="uiterm">OK</strong> when you receive the following message:
<div class="message">Changes to Connection Settings will not take effect until you restart the Database Engine service.</div>
</li>
<li>On the <strong class="uiterm">Surface Area Configuration for Services and Connections</strong> page, expand <strong class="uiterm">Database Engine</strong>,  click <strong class="uiterm">Service</strong>, click <strong class="uiterm">Stop</strong>, wait until the MSSQLSERVER service stops, and then click <strong class="uiterm">Start</strong> to restart the MSSQLSERVER service.</li>
</ol>
<h3>Enable the SQL Server Browser service:</h3>
<ol>
<li>Click <strong class="uiterm">Start</strong>, point to <strong class="uiterm">Programs</strong>, point to <strong class="uiterm">Microsoft SQL Server 2005</strong>, point to <strong class="uiterm">Configuration Tools</strong>, and then click <strong class="uiterm">SQL Server Surface Area Configuration</strong>.</li>
<li>On the <strong class="uiterm">SQL Server 2005 Surface Area Configuration</strong> page, click <strong class="uiterm">Surface Area Configuration for Services and Connections</strong>.</li>
<li>On the <strong class="uiterm">Surface Area Configuration for Services and Connections</strong> page, click <strong class="uiterm">SQL Server Browser</strong>, click <strong class="uiterm">Automatic</strong> for <strong class="uiterm">Startup type</strong>, and then click <strong class="uiterm">Apply</strong>.<strong>Note</strong> When you click the <strong class="uiterm">Automatic</strong> option, the SQL Server Browser service starts automatically every time that you start Microsoft Windows.</li>
<li>Click <strong class="uiterm">Start</strong>, and then click <strong class="uiterm">OK</strong>.</li>
</ol>
<h3>Create exceptions in Windows Firewall:</h3>
<ol>
<li>Click <strong class="uiterm">Start</strong>, point to <strong class="uiterm">Programs</strong>, point to <strong class="uiterm">Microsoft SQL Server 2005</strong>, point to <strong class="uiterm">Configuration Tools</strong>, and then click <strong class="uiterm">SQL Server Configuration Manager</strong>.</li>
<li>In SQL Server Configuration Manager, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click <strong class="uiterm">Properties</strong>.</li>
<li>On the <strong class="uiterm">SQL Server Browser Properties</strong> page, click the <strong class="uiterm">Advanced</strong> tab, locate the instance ID in the property list, and then click <strong class="uiterm">OK</strong>.</li>
</ol>
<p>To open Windows Firewall, click <strong class="uiterm">Start</strong>, click <strong class="uiterm">Run</strong>, type <span class="userInput">firewall.cpl</span>, and then click <strong class="uiterm">OK</strong></p>
<h4>Create an exception for SQL Server 2005 in Windows Firewall</h4>
<p>To create an exception for SQL Server 2005 in Windows Firewall, follow these steps:</p>
<ol>
<li>In Windows Firewall, click the <strong class="uiterm">Exceptions</strong> tab, and then click <strong class="uiterm">Add Program</strong>.</li>
<li>In the Add a Program window, click <strong class="uiterm">Browse</strong>.</li>
<li> Click the C:Program FilesMicrosoft SQL Server<var>MSSQL.1</var>MSSQLBinnsqlservr.exe executable program, click <strong class="uiterm">Open</strong>, and then click <strong class="uiterm">OK</strong>.<strong>Note</strong> The path may be different depending on where SQL Server 2005 is installed. <var>MSSQL.1</var> is a placeholder for the instance ID that you obtained in step 3  of the previous procedure.</li>
<li>Repeat steps 1 through 3 for each instance of SQL Server 2005 that needs an exception.</li>
</ol>
<h4>Create an exception for the SQL Server Browser service in Windows Firewall</h4>
<p>To create an exception for the SQL Server Browser service in Windows Firewall, follow these steps:</p>
<ol>
<li>In Windows Firewall, click the <strong class="uiterm">Exceptions</strong> tab, and then click <strong class="uiterm">Add Program</strong>.</li>
<li>In the Add a Program window, click <strong class="uiterm">Browse</strong>.</li>
<li>Click the C:Program FilesMicrosoft SQL Server90Sharedsqlbrowser.exe executable program, click <strong class="uiterm">Open</strong>, and then click <strong class="uiterm">OK</strong>.</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/217/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=217&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/26/enable-remote-connection-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Case sensitive comparisons in SQL</title>
		<link>http://sqlhelp.wordpress.com/2008/12/24/case-sensitive-comparisons-in-sql/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/24/case-sensitive-comparisons-in-sql/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 08:52:53 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL String comparisons]]></category>
		<category><![CDATA[BINARY_CHECKSUM]]></category>
		<category><![CDATA[Case sensitive comparisons in SQL]]></category>
		<category><![CDATA[comparisons in SQL]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL BINARY_CHECKSUM]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[MSSQL string compare]]></category>
		<category><![CDATA[MSSQL String comparisons tips]]></category>
		<category><![CDATA[SQL  best way to compare string]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL varbinary method]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=211</guid>
		<description><![CDATA[Case sensitive comparisons in SQL Server Some time we need to compare some data in binary see the examples: SELECT *  FROM TABLE1 WITH (NOLOCK) WHERE convert(varbinary(255), PASS) = convert(varbinary(255), 'RAGHU') Normal comparison: SELECT *  FROM TABLE1 WITH (NOLOCK) WHERE convert(varbinary(255), PASS) = convert(varbinary(255), 'Raghu') AND PASS= 'TEST' Uuse the BINARY_CHECKSUM function: SELECT *  FROM [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=211&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Case sensitive comparisons in SQL Server</strong></p>
<p>Some time we need to compare some data in binary see the examples:</p>
<p><code>SELECT *  FROM TABLE1 WITH (NOLOCK) WHERE convert(varbinary(255), PASS) = convert(varbinary(255), 'RAGHU')</code></p>
<p><strong>Normal comparison:</strong></p>
<p><code>SELECT *  FROM TABLE1 WITH (NOLOCK)</code><code> WHERE convert(varbinary(255), </code><code>PASS</code><code>) = convert(varbinary(255), 'Raghu</code><code>') AND </code><code>PASS</code><code>= '</code><code>TEST</code><code>'</code></p>
<p><strong>Uuse the BINARY_CHECKSUM function:<br />
</strong></p>
<p><code>SELECT *  FROM TABLE1 WITH (NOLOCK)</code><code> WHERE BINARY_CHECKSUM(answer) = BINARY_CHECKSUM('</code><code>TEST</code><code>')</code><strong><br />
</strong></p>
<p><strong>Use SQL Server case insensitive collation:</strong></p>
<p><code>SELECT *  FROM TABLE1 WITH (NOLOCK)</code><code> WHERE PASSWORD COLLATE SQL_Latin1_General_CP1_CS_AS = 'RAGHU</code><code>' COLLATE SQL_Latin1_General_CP1_CS_AS</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/211/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=211&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/24/case-sensitive-comparisons-in-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Sub Query Update</title>
		<link>http://sqlhelp.wordpress.com/2008/12/19/sub-query-update/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/19/sub-query-update/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 10:33:48 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL Subquery]]></category>
		<category><![CDATA[Stored Procedures]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL update with join]]></category>
		<category><![CDATA[Sub Query Update]]></category>
		<category><![CDATA[tow table update]]></category>
		<category><![CDATA[UPDATE statement using a join]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=208</guid>
		<description><![CDATA[Sub Query Update: if you want to run update query in join or by comparing other table then here is the example. UPDATE Table1 SET Price = Price * 2 WHERE ProductID IN (SELECT ID FROM Table2 WHERE ID= 51); GO Here is an equivalent UPDATE statement using a join: USE AdventureWorks; GO UPDATE Table1 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=208&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Sub Query Update:</strong><br />
if you want to run update query in join or by comparing other table then here is the example.</p>
<pre class="libCScode" style="white-space:pre-wrap;">UPDATE Table1
SET Price = Price * 2
WHERE ProductID IN
    (SELECT ID
     FROM Table2
     WHERE ID= 51);
GO</pre>
<p><strong>Here is an equivalent UPDATE statement using a join:</strong></p>
<pre class="libCScode" style="white-space:pre-wrap;">USE AdventureWorks;
GO
UPDATE Table1
SET Price = Price * 2
FROM Table1 AS t1
INNER JOIN Table2 AS t2
    ON t1.ProductID = t2.ProductID AND t2.ID= 51;
GO</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=208&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/19/sub-query-update/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>BEGIN TRANSACTION (Transact-SQL)</title>
		<link>http://sqlhelp.wordpress.com/2008/12/19/begin-transaction-transact-sql/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/19/begin-transaction-transact-sql/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 06:23:57 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[BEGIN TRANSACTION]]></category>
		<category><![CDATA[Author Raghunath Bhandari]]></category>
		<category><![CDATA[COMMIT TRANSACTION]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL roll back]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=203</guid>
		<description><![CDATA[BEGIN TRANSACTION represents a point at which the data referenced by a connection is logically and physically consistent. If errors are encountered, all data modifications made after the BEGIN TRANSACTION can be rolled back to return the data to this known state of consistency. Each transaction lasts until either it completes without errors and COMMIT [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=203&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>BEGIN TRANSACTION represents a point at which the data referenced by a connection is logically and physically consistent. If errors are encountered, all data modifications made after the BEGIN TRANSACTION can be rolled back to return the data to this known state of consistency. Each transaction lasts until either it completes without errors and COMMIT TRANSACTION is issued to make the modifications a permanent part of the database, or errors are encountered and all modifications are erased with a ROLLBACK TRANSACTION statement.</p>
<p><strong>Syntax:</strong></p>
<pre class="libCScode">BEGIN { TRAN | TRANSACTION }
    [ { transaction_name | @tran_name_variable }
      [ WITH MARK [ 'description' ] ]
    ]
[ ; ]</pre>
<p><strong>Example:</strong></p>
<p>You can catch your error in T-SQL as per my experience</p>
<pre>-- Exec spa_begintrnExample 'a'

<code>Create Proc spa_begintrnExample
@flag char(1)

AS
if @flag='a'
begin

BEGIN TRANSACTION

Update table set clm1='test'
IF (@@ERROR &lt;&gt; 0) GOTO QuitWithRollback 

Update table2 set clm12='test'
IF (@@ERROR &lt;&gt; 0) GOTO QuitWithRollback 

Delete from table3 where clm1='test'
IF (@@ERROR &lt;&gt; 0) GOTO QuitWithRollback 

Delete from table4 set clm1='test'
IF (@@ERROR &lt;&gt; 0) GOTO QuitWithRollback 

COMMIT TRANSACTION

GOTO  EndSave

QuitWithRollback:
  IF (@@TRANCOUNT &gt; 0) ROLLBACK TRANSACTION
EndSave: 

end</code></pre>
<p><strong>Remarks:<br />
</strong><br />
The local transaction started by the BEGIN TRANSACTION statement is escalated to a distributed transaction if the following actions are performed before the statement is committed or rolled back:</p>
<ul>
<li> An INSERT, DELETE, or UPDATE statement that references a remote table on a linked server is executed. The INSERT, UPDATE, or DELETE statement fails if the OLE DB provider used to access the linked server does not support the <strong>ITransactionJoin</strong> interface.</li>
<li> A call is made to a remote stored procedure when the REMOTE_PROC_TRANSACTIONS option is set to ON.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=203&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/19/begin-transaction-transact-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL RAND Function</title>
		<link>http://sqlhelp.wordpress.com/2008/12/14/sql-rand-function/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/14/sql-rand-function/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 05:12:02 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL RAND Function]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Optimization Tips]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[Introduction to SQL]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Database Optimization Tricks]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Optimization Tips]]></category>
		<category><![CDATA[SQL Programming]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL technology]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL tips for programmer]]></category>
		<category><![CDATA[sqlhelp]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[what is SQL]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=196</guid>
		<description><![CDATA[SQL RAND Function The SQL RAND() function is used to generate some random numbers at run time. Here is the syntax: Syntax RAND ( [ seed ] ) Repetitive calls of RAND() with the same seed value return the same results. For one connection, if RAND() is called with a specified seed value, all subsequent [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=196&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong> SQL RAND Function</strong></p>
<p>The SQL RAND() function is used to generate some random numbers at run time. Here is the syntax:</p>
<p><strong>Syntax</strong></p>
<pre>RAND <strong>(</strong> [ <em>seed </em>] <strong>)</strong></pre>
<p>Repetitive calls of RAND() with the same seed value return the same results.</p>
<p>For one connection, if RAND() is called with a specified seed value, all   subsequent calls of RAND() produce results based on the seeded RAND() call. For example,   the following query will always return the same sequence of numbers.</p>
<pre>SELECT RAND(100), RAND(), RAND()</pre>
<p><strong>Examples</strong>:</p>
<p>The following example produces four different random numbers that   are generated by the RAND function.</p>
<pre>DECLARE @counter smallint
SET @counter = 1
WHILE @counter &lt; 5
BEGIN
SELECT RAND() Random_Number
SET @counter = @counter + 1
END
GO</pre>
<p>The following example returns random float numbers based on three   different seed values.</p>
<pre>CREATE TABLE Random (Seed1 float, Seed5 float, Seed10 float)
INSERT INTO Random Values (RAND(1), RAND(5), RAND(10))
SELECT * FROM Random</pre>
<p>The RAND   function is a pseudorandom number generator that operates in a manner similar to   the C run-time library <strong>rand</strong> function. If no seed is provided, the system   generates its own variable seed numbers. If you call RAND with a seed value,   you must use variable seed values to generate random numbers. If you call RAND multiple times with   the same seed value, it returns the same generated value. The following script   returns the same value for the calls to RAND because they all use the same seed value:</p>
<pre>SELECT RAND(159784)
SELECT RAND(159784)
SELECT RAND(159784)</pre>
<p>A common way to generate random numbers from RAND is to include   something relatively variable as the seed value, such as adding several parts of   a GETDATE:</p>
<pre>SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )</pre>
<blockquote><p>When you use an algorithm based on GETDATE to generate seed values, RAND can still generate   duplicate values if the calls to RAND are made within the interval of the smallest datepart   used in the algorithm. This is especially likely when the calls to RAND are included in a   single batch. Multiple calls to RAND in a single batch can be executed within the same   millisecond. This is the smallest increment of DATEPART. In this case,   incorporate a value based on something other than time to generate the seed   values.</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/196/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=196&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/14/sql-rand-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Bulk Insert</title>
		<link>http://sqlhelp.wordpress.com/2008/12/12/how-to-use-bulk-insert/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/12/how-to-use-bulk-insert/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 05:14:38 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Bulk Insert]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[BCP T-SQL]]></category>
		<category><![CDATA[BCP Utility in SQL server]]></category>
		<category><![CDATA[Bulk Insert in SQL]]></category>
		<category><![CDATA[DBA help]]></category>
		<category><![CDATA[How to use BCP in SQL]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL developer tips]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Indexing Service]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[sqlhelp]]></category>
		<category><![CDATA[upload CSV file in SQL]]></category>
		<category><![CDATA[upload text file in SQL]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=192</guid>
		<description><![CDATA[Introduction Bulk Insert: The Bulk Insert task provides the quickest way to copy large amounts of data into a SQL Server table or view. For example, suppose your company stores its million-row product list on a mainframe system, but the company&#8217;s e-commerce system uses SQL Server 2005 to populate Web pages. You must update the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=192&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span>Introduction Bulk Insert:<br />
</span></strong><br />
The Bulk Insert task provides the quickest way to copy large amounts of data   into a SQL Server table or view. For example, suppose your company stores its   million-row product list on a mainframe system, but the company&#8217;s e-commerce   system uses SQL Server 2005 to populate Web pages. You must update the SQL   Server product table nightly with the master product list from the mainframe. To   update the table, you save the product list in a tab-delimited format and use   the Bulk Insert task to copy the data directly into the SQL Server table.</p>
<p>To ensure high-speed data copying, transformations cannot be performed on the   data while it is moving from the source file to the table or view.</p>
<p>You can configure the Bulk Insert task in the following ways:</p>
<ul>
<li>Specify the OLE DB connection manager to connect to the destination SQL   Server database and the table or view into which data is inserted.</li>
<li>Specify the File or Flat File connection manager to access the source file   and provide information about the source data file, such as the code page and   file type.</li>
<li>Define the format used by the Bulk Insert task, either by using a format   file or by defining the column and row delimiters of the source data. If using a   format file, specify the File connection manager to access the format   file.</li>
<li>Specify actions to perform on the destination table or view when inserting   the data. The options include whether to check constraints, enable identity   inserts, keep nulls, fire triggers, or lock the table.</li>
<li>Provide information about the batch of data to insert, such as the batch   size, the first and last row from the file to insert, the number of insert   errors that can occur before the task stops inserting rows, and the names of the   columns that will be sorted.</li>
</ul>
<blockquote><p>If the Bulk Insert task uses a Flat File connection manager to access the   source file, the task does not use the format specified in the Flat File   connection manager. Instead, the Bulk Insert task uses either the format   specified in a format file, or the values of the <strong>RowDelimiter</strong> and <strong>ColumnDelimiter</strong> properties of the task.</p></blockquote>
<p><strong>BULK INSERT (Transact-SQL)</strong></p>
<pre>BULK INSERT
   [ database_name . [ schema_name ] . | schema_name . ] [ table_name | view_name ]
      FROM 'data_file'
     [ WITH
    (
   [ [ , ] BATCHSIZE = batch_size ]
   [ [ , ] CHECK_CONSTRAINTS ]
   [ [ , ] CODEPAGE = { 'ACP' | 'OEM' | 'RAW' | 'code_page' } ]
   [ [ , ] DATAFILETYPE  =
      { 'char' | 'native'| 'widechar' | 'widenative' } ]
   [ [ , ] FIELDTERMINATOR = 'field_terminator' ]
   [ [ , ] FIRSTROW  =first_row ]
   [ [ , ] FIRE_TRIGGERS ]
   [ [ , ] FORMATFILE = 'format_file_path' ]
   [ [ , ] KEEPIDENTITY ]
   [ [ , ] KEEPNULLS ]
   [ [ , ] KILOBYTES_PER_BATCH =kilobytes_per_batch ]
   [ [ , ] LASTROW = last_row ]
   [ [ , ] MAXERRORS = max_errors ]
   [ [ , ] ORDER ( { column [ ASC | DESC ] } [ ,...n ] ) ]
   [ [ , ] ROWS_PER_BATCH = rows_per_batch ]
   [ [ , ] ROWTERMINATOR = 'row_terminator' ]
   [ [ , ] TABLOCK ]
   [ [ , ] ERRORFILE = 'file_name' ]
    )]</pre>
<p><strong>Examples</strong></p>
<p><strong> A. Using pipes to import data from a file</strong>:</p>
<p>This example imports order detail information into the   AdventureWorks.Sales.SalesOrderDetail table from the specified data   file by using a pipe (|) as the field terminator and |n as the row terminator.</p>
<pre>BULK INSERT AdventureWorks.Sales.SalesOrderDetail
FROM 'f:orderslineitem.txt'
WITH
(
FIELDTERMINATOR =' |',
ROWTERMINATOR =' |n'
)</pre>
<p><strong>B. Using the FIRE_TRIGGERS argument</p>
<p></strong>This example specifies the FIRE_TRIGGERS argument.</p>
<pre>BULK INSERT AdventureWorks.Sales.SalesOrderDetail
FROM 'f:orderslineitem.txt'
WITH
(
FIELDTERMINATOR =' |',
ROWTERMINATOR = ':n',
FIRE_TRIGGERS        )</pre>
<p><strong>C. Using line feed as a row terminator </strong></p>
<p>This example loads a file that uses the line feed as a row terminator such as a UNIX output:</p>
<pre>DECLARE @bulk_cmd varchar(1000)
SET @bulk_cmd = 'BULK INSERT AdventureWorks.Sales.SalesOrderDetail
FROM ''&lt;drive&gt;:&lt;path&gt;&lt;filename&gt;''
WITH (ROWTERMINATOR = '''+CHAR(10)+''')'
EXEC(@bulk_cmd)</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=192&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/12/how-to-use-bulk-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>What is BCP Utility in SQL server?</title>
		<link>http://sqlhelp.wordpress.com/2008/12/12/what-is-bcp-utility-in-sql-server/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/12/what-is-bcp-utility-in-sql-server/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 05:09:12 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[BCP Utility]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[BCP T-SQL]]></category>
		<category><![CDATA[BCP Utility in SQL server]]></category>
		<category><![CDATA[DBA help]]></category>
		<category><![CDATA[How to use BCP in SQL]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL developer tips]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Indexing Service]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[sqlhelp]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=188</guid>
		<description><![CDATA[Introduction BCP Utility: The bcp utility bulk copies data between an instance of Microsoft SQL Server 2005 and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into data files. Except when used [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=188&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction BCP Utility:</strong></p>
<p>The bcp utility bulk copies data between an instance of Microsoft SQL Server 2005 and a   data file in a user-specified format. The bcp utility can be   used to import large numbers of new rows into SQL Server tables or to export   data out of tables into data files. Except when used with the queryout option, the utility requires no knowledge of Transact-SQL. To import data into a   table, you must either use a format file created for that table or understand   the structure of the table and the types of data that are valid for its columns.</p>
<p><strong>Syntax</strong>:</p>
<pre>bcp {[[database_name.][owner].]{table_name | view_name} | "query"}
    {in | out | queryout | format} data_file
    [-mmax_errors] [-fformat_file] [-x] [-eerr_file]
    [-Ffirst_row] [-Llast_row] [-bbatch_size]
    [-n] [-c] [-w] [-N] [-V (60 | 65 | 70 | 80)] [-6]
    [-q] [-C { ACP | OEM | RAW | code_page } ] [-tfield_term]
    [-rrow_term] [-iinput_file] [-ooutput_file] [-apacket_size]
    [-Sserver_name[instance_name]] [-Ulogin_id] [-Ppassword]
    [-T] [-v] [-R] [-k] [-E] [-h"hint [,...n]"]</pre>
<p><strong>Examples</strong>:</p>
<p><strong>Copying Table Rows into a Data File (with a   Trusted Connection)</strong></p>
<p>The following example illustrates the out option on the   AdventureWorks.Sales.Currency table. This example creates a data   file named Currency.dat and copies the table data into it using   character format. The example assumes that you are using Windows Authentication   and have a trusted connection to the server instance on which you are running   the bcp command.</p>
<p>At a command prompt, enter the following command:</p>
<pre>bcp AdventureWorks.Sales.Currency out Currency.dat -T -c</pre>
<p><strong><br />
Copying Table Rows into a Data File (with   Mixed-Mode Authentication)</strong></p>
<p>The following example illustrates the out option on the   AdventureWorks.Sales.Currency table. This example creates a data   file named Currency.dat and copies the table data into it using   character format.</p>
<blockquote><p>he example assumes that you are using mixed-mode authentication, you   must use the -U switch to specify your login ID. Also, unless you are   connecting to the default instance of SQL Server on the local computer, use the -S switch to specify the system name and, optionally, an instance   name.</p></blockquote>
<pre>bcp AdventureWorks.Sales.Currency out
Currency.dat -c -U<em>&lt;login_id&gt; -S&lt;server_nameinstance_name&gt;</em></pre>
<p>The system will prompt you for your password.</p>
<p><strong>Copying Data from a File to a Table</strong></p>
<p>The following example illustrates the in option by using the   file created in the preceding example (Currency.dat). First,   however, this example creates an empty copy of the AdventureWorks   Sales.Currency table, Sales.Currency2, into which the data   is copied. The example assumes that you are using Windows Authentication and   have a trusted connection to the server instance on which you are running the bcp command.</p>
<p>To create the empty table, in Query Editor, enter the following   command:</p>
<pre>USE AdventureWorks;
GO
SELECT * INTO AdventureWorks.Sales.Currency2
FROM AdventureWorks.Sales.Currency WHERE 1=2</pre>
<p>To bulk copy the character data into the new table&#8211;that is, to   import the data&#8211;enter the following command at a command prompt:</p>
<pre>bcp AdventureWorks.Sales.Currency2
in Currency.dat -T -c</pre>
<p>To verify that the command succeeded, display the contents of the   table in Query Editor, and enter</p>
<pre>USE AdventureWorks;
GO
SELECT * FROM Sales.Currency2</pre>
<p><strong><br />
Copying a Specific Column into a Data File</strong></p>
<p>To copy a specific column, you can use the queryout option.   The following example copies only the Name column of the   Sales.Currency table into a data file. The example assumes that you   are using Windows Authentication and have a trusted connection to the server   instance on which you are running the bcp command.</p>
<p>At the Windows command prompt, enter:</p>
<pre>bcp "SELECT Name FROM AdventureWorks.Sales.Currency"
queryout Currency.Name.dat -T -c</pre>
<p><strong><br />
</strong></p>
<p><strong>Copying Data From a Query to a Data File</strong></p>
<p>To copy the result set from a Transact-SQL statement to a data file,   use the queryout option. The following example copies the names from the   AdventureWorks.Person.Contact table, ordered by last name then   first name, into the Contacts.txt data file. The example assumes   that you are using Windows Authentication and have a trusted connection to the   server instance on which you are running the bcp command.</p>
<p>At the Windows command prompt, enter:</p>
<pre>bcp "SELECT FirstName, LastName FROM
AdventureWorks.Person.Contact
ORDER BY LastName, Firstname"
queryout Contacts.txt -c -T</pre>
<p><strong><br />
Creating a Non-XML Format File</strong></p>
<p>a non-XML format file, Currency.fmt, for the   Sales.Currency table in the AdventureWorks database.   The example assumes that you are using Windows Authentication and have a trusted   connection to the server instance on which you are running the bcp command.</p>
<p>At the Windows command prompt, enter:</p>
<pre>bcp AdventureWorks.Sales.Currency
format nul -T -c  -f Currency.fmt</pre>
<p><strong></strong></p>
<p><strong>Creating an XML Format File</strong></p>
<p>The following example creates an XML format file named   Currency.xml for the Sales.Currency table in the   AdventureWorks database. The example assumes that you are using   Windows Authentication and have a trusted connection to the server instance on   which you are running the bcp command.</p>
<p>At the Windows command prompt, enter:</p>
<pre>bcp AdventureWorks.Sales.Currency
format nul -T -c -x -f Currency.xml</pre>
<p><strong></strong></p>
<p><strong>Using a Format File to Bulk Import with bcp</strong></p>
<p>To use a previously created format file when importing data into an   instance of SQL Server, use the -f switch with the in option. For   example, the following command bulk copies the contents of a data file,   Currency.dat, into a copy of the Sales.Currency table   (Sales.Currency2) by using the previously created format file   (Currency.xml). The example assumes that you are using Windows   Authentication and have a trusted connection to the server instance on which you   are running the bcp command.</p>
<p>At the Windows command prompt, enter:</p>
<pre>bcp AdventureWorks.Sales.Currency2
in Currency.dat -T -f Currency.xml</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=188&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/12/what-is-bcp-utility-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Tips And Tricks For Advanced MS SQL Server Developers</title>
		<link>http://sqlhelp.wordpress.com/2008/12/01/tips-and-tricks-for-advanced-ms-sql-server-developers/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/01/tips-and-tricks-for-advanced-ms-sql-server-developers/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 10:03:28 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL Tricks]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[Author Raghunath Bhandari]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Optimization Tips]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[DBA help]]></category>
		<category><![CDATA[MCP]]></category>
		<category><![CDATA[Microsoft Certified Professional]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSDN Help]]></category>
		<category><![CDATA[MSDN SQL News]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Database Optimization Tricks]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL developer tips]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Indexing Service]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Optimization Tips]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL technology]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL tips for programmer]]></category>
		<category><![CDATA[sqlhelp]]></category>
		<category><![CDATA[sqlhelp news]]></category>
		<category><![CDATA[sqlhelp WebSite Review]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Technology News]]></category>
		<category><![CDATA[Tips And Tricks For Advanced MS SQL Server Developers]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=114</guid>
		<description><![CDATA[Tips And Tricks For Advanced MS SQL Server Developers: Use “TRUNCATE TABLE” statement instead of “DELETE” clause if you want to delete all rows from a table. It is much faster then “DELETE” statement without any conditions. “TRUNCATE TABLE” frees all the space occupied by that table&#8217;s data and indexes, without logging the individual row [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=114&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Tips And Tricks For Advanced MS SQL Server Developers:</strong></p>
<ol>
<li> Use “TRUNCATE TABLE” statement instead of “DELETE” clause if you  want to delete all rows from a table. It is much faster then “DELETE”  statement without any conditions. “TRUNCATE TABLE” frees all the space  occupied by that table&#8217;s data and indexes, without logging the  individual row deletes.</li>
<li>Always use owner prefix in T-SQL  queries:<code><br />
</code></p>
<pre>SELECT mycolumn FROM dbo.mytable</pre>
<p>In this case query optimizer does not have to decide whether to  retrieve from dbo.mytable or other owner’s table and avoids  recompilation.  Recompilation results in no performance advantages of  stored procedures usage.</li>
<li> Don&#8217;t use “sp_“ as your prefix for stored procedures – it is a  reserved prefix in MS SQL server! MS SQL server searches for a stored  procedure with “sp_” prefix in the system procedures first, and only  after that looks for them in client procedures.</li>
<li> If you are unable to install MSDE at home because of unknown error –  check that you did not stop “Server” system service on you PC…</li>
<li> There are thousands of examples, when developers use “SELECT  COUNT(*)” statement. But there is another, much faster way to  accomplish the task:<code> </code>
<pre>SELECT rows FROM sysindexes WHERE id = OBJECT_ID('Table_Name') AND indid &lt; 2</pre>
</li>
<li> Include &#8220;SET NOCOUNT ON” statement in your stored procedures to greatly reduce network traffic.</li>
<li> Use the “BETWEEN” clause instead of “IN” for greater performance:<code><br />
SELECT productId FROM customer<br />
WHERE productId BETWEEN 1 AND 9</code></p>
<p>Instead of:</p>
<pre>SELECT productId
FROM customer
WHERE productId IN (1, 2, 3, 4,5,6,7,8,9)</pre>
</li>
<li>
<blockquote><p>Use Table variables &#8211; new feature of MS SQL 2000 instead of temp  tables. Table variables are created in memory, not written to the  tempdb database, and therefore they are much faster. However, be  careful to use them only with not very huge amount of data that you  want to allocate in temp tables, otherwise you can easily get the  server down.</p></blockquote>
</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=114&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/01/tips-and-tricks-for-advanced-ms-sql-server-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Database Settings Optimization Tips</title>
		<link>http://sqlhelp.wordpress.com/2008/12/01/90/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/01/90/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 06:18:19 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Database Settings]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[Database Optimization Tips]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL Database Optimization Tricks]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Optimization Tips]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL tips for programmer]]></category>
		<category><![CDATA[sqlhelp]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/2008/12/01/90/</guid>
		<description><![CDATA[Database Settings Optimization Tips You can turn off the &#8216;auto create statistics&#8217; database option.When this database option is set to true, statistics are automatically created on columns used in a predicate. By default, this database option is set to true. Because auto creation statistics results in some performance degradation, you can turn off this database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=90&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#008000;"><strong>Database Settings Optimization Tips</strong></span></p>
<ul>
<li><strong>You can turn off the &#8216;auto create statistics&#8217; database option.</strong>When this database option is set to true, statistics are automatically created on columns used in a predicate. By default, this database option is set to true. Because auto creation statistics results in some performance degradation, you can turn off this database option and create statistics manually during off-peak times by using the CREATE STATISTICS statement. By the way, in most cases, it will not provide some performance benefits.</li>
<li><strong>You can turn off the &#8216;auto update statistics&#8217; database option.</strong>When this database option is set to true, existing statistics are automatically updated when the statistics become out-of-date. By default, this database option is set to true. Because auto update statistics results in some performance degradation, you can turn off this database option and update statistics manually during off-peak times by using the UPDATE STATISTICS statement. By the way, in most cases, it will not provide some performance benefits.</li>
<li><strong>Turn off the &#8216;autoclose&#8217; database option.</strong>When this option is turned on, the database&#8217;s resources are freed after the last user exits. When the new user will connect to database, the database should be reopened, which takes some time. So, do hot set this database option to true on your production server. By default, this database option is set to true when using SQL Server Desktop Edition, and set to false for all other editions.</li>
<li><strong>Turn off the &#8216;autoshrink&#8217; database option.</strong>When this database option is set to true, the database files will be periodically shrink. Autoshrinking results in some performance degradation, therefore you should shrink the database manually or create a scheduled task to shrink the database periodically during off-peak times, rather than set Autoshrink feature to on. By default, this database option is set to true when using SQL Server Desktop Edition, and set to false for all other editions.</li>
<li><strong>You can turn on the &#8216;read-only&#8217; database option to prevent users to modify the database&#8217;s data.</strong>By default, this database option is set to false. If you have data that should not be modified, you can place it into another database and set for this database the &#8216;read-only&#8217; option to true. It can increase the speed of your queries. If you need to allow permissions management (for example, prevent some users to select data from some tables), you should create another filegroup and make only this filegroup read-only, because when the &#8216;read-only&#8217; database option is set to true, the database&#8217;s system tables will be also read-only and this will prevent the permissions management.</li>
<li><strong>You can turn on the &#8216;select into/bulkcopy&#8217; database option to allow SELECT INTO statements and nonlogged bulk copies.</strong>The nonlogged bulk copy is		 	much faster than logged one, but to use it you must provide all the following conditions:1. The database option &#8216;select into/bulkcopy&#8217; is set to true.<br />
<blockquote><p>2. The target table is not being replicated.<br />
3. The TABLOCK hint is specified.<br />
4. The target table has no indexes, or if the table has indexes, it is empty when the bulk copy starts.<br />
By default, this database option is set to false.</p></blockquote>
</li>
<li><strong>You can turn off the &#8216;trunc. log on chkpt.&#8217; database option to prevent the transaction log from truncating on checkpoint.</strong>This option can be set if the transaction log grows very quickly to prevent the transaction log from filling rapidly and running out of disk space. If you set the &#8216;trunc. log on chkpt.&#8217; database option to true, the transaction log cannot be backed up, so you cannot restore your data to the point of failure (only to the time when the last full backup was made). So, the general recommendation about this option is allow it to be turned off, and make the transaction log backup periodically to truncate the log. By default, this database option is set to true when using SQL Server Desktop Edition, and set to false for all other editions.</li>
</ul>
<blockquote><p><strong> Note. You can set the above database options by using the sp_dboption system stored procedure or Enterprise Manager. If you want to set the above database options for the newly created database, you should set these options for the model database.</strong></p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=90&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/01/90/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server Settings Optimization Tips</title>
		<link>http://sqlhelp.wordpress.com/2008/12/01/sql-server-settings-optimization-tips/</link>
		<comments>http://sqlhelp.wordpress.com/2008/12/01/sql-server-settings-optimization-tips/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 05:27:26 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[Database Optimization Tips]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL Database Optimization Tricks]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Optimization Tips]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL tips for programmer]]></category>
		<category><![CDATA[sqlhelp]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=75</guid>
		<description><![CDATA[SQL Server Settings Optimization Tips: You can increase the &#8216;min memory per query&#8217; option to improve the performance of queries that use hashing or sorting operations, if your SQL Server has a lot of memory available and there are many queries running concurrently on the server. The SQL Server will automatically allocate, at a minimum, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=75&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#008000;"><strong>SQL Server Settings Optimization Tips:</strong></span></p>
<ol>
<li> <strong>You can increase the &#8216;min memory per query&#8217; option to improve the performance of queries that use hashing or sorting operations, if your SQL Server has a lot of memory available and there are many queries running concurrently on the server.</strong><br />
The SQL Server will automatically allocate, at a minimum, the amount of memory set in this configuration setting. The default &#8216;min memory per query&#8217; option is equal to 1024 Kb.</li>
<li><strong>You can increase the &#8216;max async IO&#8217; option if your SQL Server works on a high performance server with high-speed intelligent disk subsystem (such as hardware-based RAID with more than 10 disks).</strong><br />
This option specifies the maximum number of outstanding asynchronous disk I/O requests that the entire server can issue against a file. By the way, the &#8216;max async IO&#8217; SQL Server option is no longer supported in SQL Server 2000.</li>
<li><strong>You can change the &#8216;network packet size&#8217; option to the appropriate value.</strong><br />
This option can improve performance on networks whose base topology supports larger packets than TCP/IP&#8217;s default of 4096 bytes. For example, if client sends or receives large amounts of data, a larger packet size can improve performance, because it results in fewer network reads and writes. The default value for the &#8216;network packet size&#8217; option is 4096 bytes. Microsoft does not recommend changing this option, because for most applications, the default packet size of 4096 bytes is best.</li>
<li><strong>You can change the &#8216;fill factor&#8217; option to the appropriate value.</strong><br />
<blockquote><p>The &#8216;fill factor&#8217; option specifies how full SQL Server will make each index page. When there is no free space to insert new row on the index page, SQL Server will create new index page and transfer some rows from the previous page to the new one. This operation is called page splits. You can reduce the number of page splits by setting the appropriate fill factor option to reserve free space on each index page. The fill factor is a value from 1 through 100 that specifies the percentage of the index page to be left empty. The default value for fill factor is 0. It is treated similarly to a fill factor value of 100, the difference in that SQL Server leaves some space within the upper level of the index tree for FILLFACTOR = 0. The fill factor percentage is used only at the time the index is created. If the table contains read-only data (or data that very rarely changed), you can set the &#8216;fill factor&#8217; option to 100. When the table&#8217;s data modified very often, you can decrease the &#8216;fill factor&#8217; option to 70 percent, for example.</p></blockquote>
</li>
<li><strong>You can increase the &#8216;recovery interval&#8217; value.</strong><br />
The &#8216;recovery interval&#8217; option specifies the maximum number of minutes per database that SQL Server needs to complete its recovery procedures. The default value of this option is 0. It means that SQL Server will automatically configure this option. SQL Server issues a checkpoint using the &#8216;recovery interval&#8217; option. Microsoft does not recommend changing this option in general case, but sometimes you can improve performance by changing this option. You can monitor disk-write activity on the data files, and if you see periodic spikes that send disk utilization to 100 percent, you can increase the recovery interval. In this case, Microsoft suggests setting the &#8216;recovery interval&#8217; option to 5 and continuing monitoring.<br />
<strong></strong></li>
<li><strong>You can set the &#8216;priority boost&#8217; SQL Server options to 1.</strong><br />
You can set this option to 1, if you want from SQL Server to work with a higher priority than other processes on the same computer. The default value is 0. Setting &#8216;priority boost&#8217; to 1 can degrade the performance of other applications running on the same computer with SQL Server. So, you should set the &#8216;priority boost&#8217; SQL Server options to 1 only if you have dedicated server to SQL Server. In other case, do not change this option.</li>
<li><strong>Set the &#8216;max worker threads&#8217; options to the maximum number of the user connections to your SQL Server box.</strong><br />
The default setting for the &#8216;max worker threads&#8217; option is 255. If the number of user connections will be less than the &#8216;max worker threads&#8217; value, a separate operating system thread will be created for each client connection, but if the number of user connections will exceed this value the thread pooling will be used. For example, if the maximum number of the user connections to your SQL Server box is equal to 50, you can set the &#8216;max worker threads&#8217; options to 50, this frees up resources for SQL Server to use elsewhere. If the maximum number of the user connections to your SQL Server box is equal to 500, you can set the &#8216;max worker threads&#8217; options to 500, this can improve SQL Server performance because thread pooling will not be used.</li>
<li><strong>You can specify the &#8216;min server memory&#8217; and &#8216;max server memory&#8217; options.</strong><br />
These options can be used to specify the fixed amount of memory to allocate to SQL Server. In this case, you should set the &#8216;min server memory&#8217; and &#8216;max server memory&#8217; to the same value (equal to the maximum amount of physical memory that SQL Server will use), and set the &#8216;set working set size&#8217; SQL Server option to 1. This can improve performance because SQL Server will not dynamically allocate memory. You can also change these options when SQL Server works on the same computer with other applications. In this case, the &#8216;min server memory&#8217; options is used to allow SQL Server works when other applications pretend to use all available memory, and the &#8216;max server memory&#8217; options is used to allow other applications work when SQL Server tried to use all available resources.</li>
<li><strong>You can specify the &#8216;set working set size&#8217; SQL Server option to reserve the amount of physical memory space for SQL Server.</strong><br />
Unlike SQL Server 6.5, SQL Server 7.0/2000 can automatically allocate memory (can take more memory if SQL Server need it, and can give memory back to operation system). This is one of the main advantages in comparison with previous versions, but dynamic memory allocation takes some time. If you know the maximum amount of physical memory that SQL Server will use, you can specify this amount by setting &#8216;min server memory&#8217; and &#8216;max server memory&#8217; to the same value (equal to the maximum amount of physical memory that SQL Server will use) and set the &#8216;set working set size&#8217;</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=75&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/12/01/sql-server-settings-optimization-tips/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Basic Definitions</title>
		<link>http://sqlhelp.wordpress.com/2008/11/30/basic-definitions/</link>
		<comments>http://sqlhelp.wordpress.com/2008/11/30/basic-definitions/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 07:05:24 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Basic Definitions]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Optimization Tips]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Basic Definitions]]></category>
		<category><![CDATA[SQL Database Optimization Tricks]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Optimization Tips]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL technology]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL tips for programmer]]></category>
		<category><![CDATA[sqlhelp]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=59</guid>
		<description><![CDATA[Definition of a Database A database is a collection of related information, accessed and managed by its DBMS. After experimenting with hierarchical and networked DBMSs during the 1970’s, the IT industry became dominated by relational DBMSs (Or Object-Relational Database Management System) such as Informix database, Oracle, Sybase, and, later on, Microsoft SQL Server and the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=59&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Definition of a Database</strong></p>
<p>A database is a collection of related information, accessed and managed by its DBMS. After experimenting with hierarchical and networked DBMSs during the 1970’s, the IT industry became dominated by relational DBMSs (Or Object-Relational Database Management System) such as Informix database, Oracle, Sybase, and, later on, Microsoft SQL Server and the like.</p>
<p>In a strictly technical sense, for any database to be defined as a &#8220;Truly Relational Model Database Management System,&#8221; it should, ideally, adhere to the twelve rules defined by Edgar F. Codd, pioneer in the field of relational databases. To date, while many come close, it is admitted that nothing on the market adheres 100% to those rules, any more than they are 100% ANSI-SQL compliant.</p>
<blockquote><p>While IBM and Oracle technically were the earliest on the RDBMS scene, many others have followed, and while it is unlikely that miniSQL still exist in their original form, Monty&#8217;s MySQL is still extant and thriving, along with the Ingres-descended PostgreSQL. Microsoft Access &#8211; the 1995+ versions, not the prior versions &#8211; were, despite various limitations, technically the closest thing to being &#8216;Truly Relational&#8217; DBMS&#8217;s for the desktop PC, with Visual FoxPro, and many other desktop products marketed at that time far less compliant with Codd&#8217;s Rules.</p></blockquote>
<p>A relational DBMS manages information about types of real-world things (entities) in the form of tables that represent the entities. A table is like a spreadsheet; each row represents a particular entity (instance&#8212;), and each column represents a type of information about the entity (domain). Sometimes entities are made up of smaller related entities, such as orders and order lines; and so one of the challenges of a multi-user DBMS is provide data about related entities from the standpoint of an instant of logical consistency.</p>
<p>Properly managed relational databases minimize the need for application programs to contain information about the physical storage of the data they access. To maximize the isolation of programs from data structures, relational DBMSs restrict data access to the messaging protocol SQL, a nonprocedural language that limits the programmer to specifying desired results. This message-based interface was a building block for the decentralization of computer hardware, because a program and data structure with such a minimal point of contact become feasible to reside on separate computers.</p>
<p><strong>Recoverability</strong></p>
<p>Recoverability means that, if a data entry error, program bug or hardware failure (Vista) occurs, the DBA can bring the database backward in time to its state at an instant of logical consistency before the damage was done. Recoverability activities include making database backups and storing them in ways that minimize the risk that they will be damaged or lost, such as placing multiple copies on removable media and storing them outside the affected area of an anticipated disaster. Recoverability is the DBA’s most important concern.</p>
<p>The backup of the database consists of data with timestamps combined with database logs to change the data to be consistent to a particular moment in time. It is possible to make a backup of the database containing only data without timestamps or logs, but the DBA must take the database offline to do such a backup.</p>
<p>The recovery tests of the database consist of restoring the data, then applying logs against that data to bring the database backup to consistency at a particular point in time up to the last transaction in the logs. Alternatively, an offline database backup can be restored simply by placing the data in-place on another copy of the database.</p>
<blockquote><p>If a DBA (or any administrator) attempts to implement a recoverability plan without the recovery tests, there is no guarantee that the backups are at all valid. In practice, in all but the most mature RDBMS packages, backups rarely are valid without extensive testing to be sure that no bugs or human error have corrupted the backups.</p></blockquote>
<p><strong>Security</strong><br />
Security means that users’ ability to access and change data conforms to the policies of the business and the delegation decisions of its managers. Like other metadata, a relational DBMS manages security information in the form of tables. These tables are the “keys to the kingdom” and so it is important to protect them from intruders.<br />
<strong><br />
Performance</strong></p>
<p>Performance means that the database does not cause unreasonable online response times, and it does not cause unattended programs to run for an unworkable period of time. In complex client/server and three-tier systems, the database is just one of many elements that determine the performance that online users and unattended programs experience. Performance is a major motivation for the DBA to become a generalist and coordinate with specialists in other parts of the system outside of traditional bureaucratic reporting lines.</p>
<p>Techniques for database performance tuning have changed as DBA&#8217;s have become more sophisticated in their understanding of what causes performance problems and their ability to diagnose the problem.</p>
<p>In the 1990s, DBAs often focused on the database as a whole, and looked at database-wide statistics for clues that might help them find out why the system was slow. Also, the actions DBAs took in their attempts to solve performance problems were often at the global, database level, such as changing the amount of computer memory available to the database, or changing the amount of memory available to any database program that needed to sort data.</p>
<blockquote><p>DBA&#8217;s now understand that performance problems initially must be diagnosed, and this is best done by examining individual SQL statements, table process, and system architecture, not the database as a whole. Various tools, some included with the database and some available from third parties, provide a behind the scenes look at how the database is handling the SQL statements, shedding light on what&#8217;s taking so long.Having identified the problem, the individual SQL statement can be clarify</p></blockquote>
<p><strong>Development/Testing Support</strong></p>
<p>Development and testing support is typically what the database administrator regards as his or her least important duty, while results-oriented managers consider it the DBA’s most important duty. Support activities include collecting sample production data for testing new and changed programs and loading it into test databases; consulting with programmers about performance tuning; and making table design changes to provide new kinds of storage for new program functions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=59&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/11/30/basic-definitions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>Indexing Service</title>
		<link>http://sqlhelp.wordpress.com/2008/11/30/indexing-service/</link>
		<comments>http://sqlhelp.wordpress.com/2008/11/30/indexing-service/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 06:35:48 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[Indexing Service]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[Author Raghunath Bhandari]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Optimization Tips]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[MCP]]></category>
		<category><![CDATA[Microsoft Certified Professional]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSDN Help]]></category>
		<category><![CDATA[MSDN SQL News]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Database Optimization Tricks]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Indexing Service]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Optimization Tips]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL technology]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL tips for programmer]]></category>
		<category><![CDATA[sqlhelp]]></category>
		<category><![CDATA[sqlhelp news]]></category>
		<category><![CDATA[sqlhelp WebSite Review]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Technology News]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=52</guid>
		<description><![CDATA[What is Indexing Service? Indexing Service is a base service for Microsoft® Windows® 2000 or later that extracts content from files and constructs an indexed catalog to facilitate efficient and rapid searching. Indexing Service can extract both text and property information from files on the local host and on remote, networked hosts. The files can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=52&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>What is Indexing Service?</strong></p>
<p>Indexing Service is a base service for Microsoft® Windows® 2000 or later that extracts content from files and constructs an indexed catalog to facilitate efficient and rapid searching.</p>
<p>Indexing Service can extract both text and property information from files on the local host and on remote, networked hosts. The files can be simply members of a selected file system or part of a virtual Web hosted by, for example, Internet Information Services (IIS).</p>
<p>Indexing Service extracts the content by filtering—using filter components that understand a file&#8217;s format. The format could include multi-language features such as international languages and locales. A filter component implements the IFilter interface, which supplies methods to read a file to extract text and properties. Windows 2000 and Microsoft Windows XP supply filters for Microsoft Office files, Hypertext Markup Language (HTML) files, Multipurpose Internet Mail Extension (MIME) messages, and plain-text files.</p>
<p>Indexing Service then merges the extracted information into catalogs of indexes for efficient searches. Indexing is the overall process of filtering, creating index entries, and merging them into catalogs.</p>
<p>The final step in the indexing process is creation of a catalog that contains a master index (and any temporary word lists and shadow indexes) storing words and their locations within a set of indexed documents. Subsequently, searching, or querying, the catalogs for particular word combinations uses the master index as well as word lists and shadow indexes to execute queries quickly and efficiently.</p>
<p><strong>Windows 2000 and Windows XP include basic facilities for querying the Indexing Service catalog and for managing the state and properties of Indexing Service itself. These facilities include:</strong></p>
<ul>
<li> When Indexing Service is running, Start/Search/For Files or Folders uses the Indexing Service catalog.</li>
<li>The Indexing Service snap-in for the Microsoft Management Console (MMC) provides the means to start, stop, and pause Indexing Service, and to administer many of its properties, such as those defining its catalogs.</li>
<li>The Platform Software Development Kit (SDK) provides additional versatile and flexible facilities for programmatically interacting with Indexing Service. These facilities include:</li>
<li> Admin and Query Helper objects and ActiveX® Data Object (ADO) methods for use with Microsoft Visual Basic®, Microsoft Visual Basic Scripting Edition (VBScript), Microsoft Visual J++® and Microsoft JScript® development software.</li>
<li>ISAPI Extensions for use in .idq, .ida, and .htx files.</li>
<li>OLE DB Helper functions for use with Microsoft Visual C++® development system.</li>
<li>OLE DB Provider for Indexing Service interfaces for use with Visual C++.</li>
<li>IFilter interface for use with Visual C++</li>
</ul>
<p><strong>Source: MSDN</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=52&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/11/30/indexing-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Performance Tuning using Indexes</title>
		<link>http://sqlhelp.wordpress.com/2008/11/28/sql-performance-tuning-using-indexes/</link>
		<comments>http://sqlhelp.wordpress.com/2008/11/28/sql-performance-tuning-using-indexes/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 10:37:25 +0000</pubDate>
		<dc:creator>Raghunath Bhandari</dc:creator>
				<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[Advance SQL tips and tricks]]></category>
		<category><![CDATA[Author Raghunath Bhandari]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Optimization Tips]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[MCP]]></category>
		<category><![CDATA[Microsoft Certified Professional]]></category>
		<category><![CDATA[Microsoft SQL server]]></category>
		<category><![CDATA[MSDN Help]]></category>
		<category><![CDATA[MSDN SQL News]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MSSQL server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Database Optimization Tricks]]></category>
		<category><![CDATA[SQL Database Settings Optimization Tips]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL help]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Optimization Tips]]></category>
		<category><![CDATA[SQL Performance Tuning using Indexes]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL server tips]]></category>
		<category><![CDATA[SQL technology]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL tips for programmer]]></category>
		<category><![CDATA[sqlhelp]]></category>
		<category><![CDATA[sqlhelp news]]></category>
		<category><![CDATA[sqlhelp WebSite Review]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Technology News]]></category>

		<guid isPermaLink="false">http://sqlhelp.wordpress.com/?p=44</guid>
		<description><![CDATA[SQL Performance Tuning using Indexes This article looks at general guidelines to creating effective indexes using short keys, distinct keys, covering indexes and clustered indexes. Effective indexes are one of the best ways to improve performance in a database application. Without an index, the SQL Server engine is like a reader trying to find a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=44&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>SQL Performance Tuning using Indexes</strong></p>
<p><em>This article looks at general guidelines to creating effective indexes using short keys, distinct keys, covering indexes and clustered indexes.<br />
</em></p>
<p><span style="color:#ff0000;">Effective indexes are one of the best ways to improve performance in a database application. Without an index, the SQL Server engine is like a reader trying to find a word in a book by examining each page. By using the index in the back of a book, a reader can complete the task in a much shorter time. In database terms, a table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance.</span></p>
<p><span style="color:#ff0000;">One of the most important jobs for the database is finding the best index to use when generating an execution plan. Most major databases ship with tools to show you execution plans for a query and help in optimizing and tuning indexes. This article outlines several good rules of thumb to apply when creating and modifying indexes for your database. First, let’s cover the scenarios where indexes help performance, and when indexes can hurt performance.</span></p>
<p><strong>Useful Index Queries</strong></p>
<p>Just like the reader searching for a word in a book, an index helps when you are looking for a specific record or set of records with a WHERE clause. This includes queries looking for a range of values, queries designed to match a specific value, and queries performing a join on two tables. For example, both of the queries against the Northwind database below will benefit from an index on the UnitPrice column.</p>
<p><code>DELETE FROM Products WHERE UnitPrice = 1</code></p>
<p>SELECT * FROM PRODUCTS<br />
WHERE UnitPrice BETWEEN 14 AND 16</p>
<p>Since index entries are stored in sorted order, indexes also help when processing ORDER BY clauses. Without an index the database has to load the records and sort them during execution. An index on UnitPrice will allow the database to process the following query by simply scanning the index and fetching rows as they are referenced. To order the records in descending order, the database can simply scan the index in reverse.</p>
<p><code>SELECT * FROM Products ORDER BY UnitPrice ASC</code></p>
<p>Grouping records with a GROUP BY clause will often require sorting, so a UnitPrice index will also help the following query to count the number of products at each price.<br />
<code><br />
SELECT Count(*), UnitPrice FROM Products<br />
GROUP BY UnitPrice</code></p>
<p>By retrieving the records in sorted order through the UnitPrice index, the database sees matching prices appear in consecutive index entries, and can easily keep a count of products at each price. Indexes are also useful for maintaining unique values in a column, since the database can easily search the index to see if an incoming value already exists. Primary keys are always indexed for this reason.</p>
<p><strong>Index Drawbacks</strong></p>
<p>Indexes are a performance drag when the time comes to modify records. Any time a query modifies the data in a table the indexes on the data must change also. Achieving the right number of indexes will require testing and monitoring of your database to see where the best balance lies. Static systems, where databases are used heavily for reporting, can afford more indexes to support the read only queries. A database with a heavy number of transactions to modify data will need fewer indexes to allow for higher throughput. Indexes also use disk space. The exact size will depends on the number of records in the table as well as the number and size of the columns in the index. Generally this is not a major concern as disk space is easy to trade for better performance.</p>
<p><strong>Building The Best Index</strong></p>
<p>There are a number of guidelines to building the most effective indexes for your application. From the columns you select to the data values inside them, consider the following points when selecting the indexes for your tables.</p>
<p><strong>Short Keys</strong></p>
<p>Having short index is beneficial for two reasons. First, database work is inherently disk intensive. Larger index keys will cause the database to perform more disk reads, which limits throughput. Secondly, since index entries are often involved in comparisons, smaller entries are easier to compare. A single integer column makes the absolute best index key because an integer is small and easy for the database to compare. Character strings, on the other hand, require a character by character comparison and attention to collation settings.</p>
<p><strong>Distinct Keys</strong></p>
<p>The most effective indexes are the indexes with a small percentage of duplicated values. As an analogy, think of a phone book for a town where almost everyone has the last name of Smith. A phone book in this town is not very useful if sorted in order of last name, because you can only discount a small number of records when you are looking for a Smith.</p>
<p>An index with a high percentage of unique values is a selective index. Obviously, a unique index is highly selective since there are no duplicate entries. Many databases will track statistics about each index so they know how selective each index is. The database uses these statistics when generating an execution plan for a query.</p>
<p><strong><br />
Covering Queries</strong></p>
<p>Indexes generally contain only the data values for the columns they index and a pointer back to the row with the rest of the data. This is similar to the index in a book: the index contains only the key word and then a page reference you can turn to for the rest of the information. Generally the database will have to follow pointers from an index back to a row to gather all the information required for a query. However, if the index contains all of he columns needed for a query, the database can save a disk read by not returning to the table for more information.</p>
<p>Take the index on UnitPrice we discussed earlier. The database could use just the index entries to satisfy the following query.</p>
<p><code>SELECT Count(*), UnitPrice FROM Products<br />
GROUP BY UnitPrice<br />
</code></p>
<p>We call these types of queries covered queries, because all of the columns requested in the output are covered by a single index. For your most crucial queries, you might consider creating a covering index to give the query the best performance possible. Such an index would probably be a composite index (using more than one column), which appears to go against our first guideline of keeping index entries as short as possible. Obviously this is another tradeoff you can only evaluate with performance testing and monitoring.</p>
<p><strong>Clustered Indexes</strong></p>
<p>Many databases have one special index per table where all of the data from a row exists in the index. SQL Server calls this index a clustered index. Instead of an index at the back of a book, a clustered index is closer in similarity to a phone book because each index entry contains all the information you need, there are no references to follow to pick up additional data values.</p>
<p>As a general rule of thumb, every non-trivial table should have a clustered index. If you only create one index for a table, make the index a clustered index. In SQL Server, creating a primary key will automatically create a clustered index (if none exists) using the primary key column as the index key. Clustered indexes are the most effective indexes (when used, they always cover a query), and in many databases systems will help the database efficiently manage the space required to store the table.</p>
<p>When choosing the column or columns for a clustered index, be careful to choose a column with static data. If you modify a record and change the value of a column in a clustered index, the database might need to move the index entry (to keep the entries in sorted order). Remember, index entries for a clustered index contain all of the column values, so moving an entry is comparable to executing a DELETE statement followed by an INSERT, which can obviously cause performance problems if done often. For this reason, clustered indexes are often found on primary or foreign key columns. Key values will rarely, if ever, change.</p>
<p><strong>Conclusion<br />
</strong></p>
<p>Determining the correct indexes to use in a database requires careful analysis, benchmarking, and testing. The rules of thumb presented in this article are general guidelines. After applying these principals you need to retest your specific application in your specific environment of hardware, memory, and concurrent activity. See my previous article: SQL Server Indexes, for a more thorough introduction.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlhelp.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlhelp.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlhelp.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlhelp.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlhelp.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlhelp.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlhelp.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlhelp.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlhelp.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlhelp.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlhelp.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlhelp.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlhelp.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlhelp.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlhelp.wordpress.com&amp;blog=5672629&amp;post=44&amp;subd=sqlhelp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlhelp.wordpress.com/2008/11/28/sql-performance-tuning-using-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344460fcb9807a37c97174a2edc9d970?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Raghunath Bhandari</media:title>
		</media:content>
	</item>
	</channel>
</rss>
