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

<channel>
	<title>Michael Sync &#187; Microsoft SQL</title>
	<atom:link href="http://michaelsync.net/category/microsoft-sql/feed" rel="self" type="application/rss+xml" />
	<link>http://michaelsync.net</link>
	<description>Sharing our knowledge</description>
	<lastBuildDate>Tue, 10 Jan 2012 02:18:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Identity</title>
		<link>http://michaelsync.net/2006/07/14/identity</link>
		<comments>http://michaelsync.net/2006/07/14/identity#comments</comments>
		<pubDate>Fri, 14 Jul 2006 04:55:25 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Microsoft SQL]]></category>

		<guid isPermaLink="false">http://michaelsync.net/2006/07/14/identity</guid>
		<description><![CDATA[/* Getting the current value of identity column of a table. */SELECTIDENT_CURRENT(&#8216;Invoice&#8217;) /* OR */ DBCC CHECKIDENT (invoice,NORESEED) /* Getting the incremental values of identity column of all tables from one database. */ USE training2005SELECT TABLE_NAME,IDENT_INCR(TABLE_NAME)AS IDENT_INCR FROM INFORMATION_SCHEMA.TABLESWHERE IDENT_INCR(TABLE_NAME)IS &#8230; <a href="http://michaelsync.net/2006/07/14/identity">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table cellpadding="0" cellspacing="0" border="0" width="464">
<tr>
<td width="448">
<p><font color="#008000" face="Courier New" size="2">/*<br /> Getting the current value of identity column of a table. <br /> */<br /></font><font color="#0000FF" face="Courier New" size="2">SELECT</font><font color="#008000" face="Courier New" size="2"><br /></font><font color="#FF00FF" face="Courier New" size="2">IDENT_CURRENT</font><font color="#008000" face="Courier New" size="2">(</font><font color="#FF0000" face="Courier New" size="2">&#8216;Invoice&#8217;</font><font color="#008000" face="Courier New" size="2">)</p>
<p>/* OR */</p>
<p></font><font color="#0000FF" face="Courier New" size="2">DBCC</font><font color="#008000" face="Courier New" size="2"> </font><font color="#000000" face="Courier New" size="2"> CHECKIDENT (invoice,NORESEED)</font></p>
<p><font color="#008000" face="Courier New" size="2"></p>
<p>/* <br /> Getting the incremental values of identity column of all tables from one database. <br />*/ <br /><font color="#0000FF" face="Courier New" size="2">USE</font> <font color="#000000" face="Courier New" size="2">training2005</font><font color="#008000" face="Courier New" size="2"><br /></font><font color="#0000FF" face="Courier New" size="2">SELECT</font></font><font color="#0000FF" face="Courier New" size="2"></font><font color="#008000" face="Courier New" size="2"> <font color="#000000" face="Courier New" size="2">TABLE_NAME</font><font color="#008000" face="Courier New" size="2">,</font><font color="#FF00FF" face="Courier New" size="2">IDENT_INCR</font><font color="#008000" face="Courier New" size="2">(</font><font color="#000000" face="Courier New" size="2">TABLE_NAME</font><font color="#008000" face="Courier New" size="2">)</font><font color="#0000FF" face="Courier New" size="2">AS</font><font color="#008000" face="Courier New" size="2"><br /></font><font color="#FF00FF" face="Courier New" size="2"> IDENT_INCR</font> <font color="#0000FF" face="Courier New" size="2">FROM</font><font color="#008000" face="Courier New" size="2"> INFORMATION_SCHEMA.TABLES<br /></font><font color="#0000FF" face="Courier New" size="2">WHERE</font> <font color="#FF00FF" face="Courier New" size="2">IDENT_INCR</font><font color="#008000" face="Courier New" size="2">(</font><font color="#000000" face="Courier New" size="2">TABLE_NAME</font><font color="#008000" face="Courier New" size="2">)</font><font color="#808080" face="Courier New" size="2">IS NOT NULL</font><font color="#008000" face="Courier New" size="2"></p>
<p>/* <br />Getting the incremental value of identity column of a tables. <br />*/<br /></font><font color="#0000FF" face="Courier New" size="2">SELECT</font> <font color="#000000" face="Courier New" size="2">TABLE_NAME</font><font color="#008000" face="Courier New" size="2">,</font><font color="#FF00FF" face="Courier New" size="2">IDENT_INCR</font><font color="#008000" face="Courier New" size="2">(</font><font color="#000000" face="Courier New" size="2">TABLE_NAME</font><font color="#008000" face="Courier New" size="2">)<br /></font><font color="#0000FF" face="Courier New" size="2"> AS</font> <font color="#FF00FF" face="Courier New" size="2">IDENT_INCR</font><font color="#0000FF" face="Courier New" size="2">FROM</font><font color="#008000" face="Courier New" size="2"> INFORMATION_SCHEMA.TABLES<br /></font><font color="#0000FF" face="Courier New" size="2">WHERE</font> <font color="#FF00FF" face="Courier New" size="2">IDENT_INCR</font><font color="#008000" face="Courier New">(</font><font color="#000000" face="Courier New" size="2">TABLE_NAME</font><font color="#008000" face="Courier New" size="2">)<br /></font><font color="#808080" face="Courier New" size="2"> IS NOT NULL AND</font><font color="#000000" face="Courier New" size="2">TABLE_NAME</font><font color="#008000" face="Courier New" size="2">=</font><font color="#FF0000" face="Courier New" size="2">&#8216;Invoice&#8217;</font></p>
<p>/* <br />Getting the start values<br />of identity column of all tables from one database <br />*/<br /><font size="2" face="Courier New"><font color="#0000FF">USE</font> training2005<br /><font color="#0000FF">SELECT</font> TABLE_NAME, <font color="#FF00FF">IDENT_SEED</font>(TABLE_NAME)<br /><font color="#0000FF"> AS</font> <font color="#FF00FF"> IDENT_SEED</font> <font color="#0000FF">FROM</font> <font color="#008000"> INFORMATION_SCHEMA.TABLES</font><br /><font color="#0000FF">WHERE</font> <font color="#FF00FF">IDENT_SEED</font>(TABLE_NAME)<font color="#808080">IS NOT NULL </font></font></p>
<p><font face="Courier New" size="2"><font color="#008000">/* <br /> Getting the startvalue of identity column of a table. <br />*/</font><br /><font color="#0000FF">SELECT</font> TABLE_NAME, <font color="#FF00FF">IDENT_SEED</font>(TABLE_NAME)<font color="#0000FF">AS</font> <font color="#FF00FF"> IDENT_SEED</font><br /><font color="#0000FF">FROM</font> <font color="#008000"> INFORMATION_SCHEMA.TABLES</font><font color="#0000FF">WHERE</font> <font color="#FF00FF">IDENT_SEED</font>(TABLE_NAME) IS NOT NULL AND<br />TABLE_NAME=<font color="#FF0000">&#8216;Invoice&#8217;</font></font></p>
</td>
</tr>
</table>
<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://michaelsync.net/2006/07/14/identity&#038;layout=standard&#038;show_faces=false&#038;width=450&#038;height=25&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px;"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://michaelsync.net/2006/07/14/identity/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL 2k Tips : UPDATETEXT</title>
		<link>http://michaelsync.net/2006/07/04/sql-2k-tips-updatetext</link>
		<comments>http://michaelsync.net/2006/07/04/sql-2k-tips-updatetext#comments</comments>
		<pubDate>Tue, 04 Jul 2006 11:06:44 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Microsoft SQL]]></category>

		<guid isPermaLink="false">http://michaelsync.net/2006/07/04/sql-2k-tips-updatetext</guid>
		<description><![CDATA[I have received the email from Grace on Tuesday, February 01, 2005 4:07 PM. Wow! She was sharing some interesting things related to SQL. Thank you so much, Grace! Hi Micheal, Do you know that ntext data type can’t do &#8230; <a href="http://michaelsync.net/2006/07/04/sql-2k-tips-updatetext">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have received the email from Grace on Tuesday, February 01, 2005 4:07 PM. Wow! She was sharing some interesting things related to SQL.<br />
Thank you so much, Grace!</p>
<p>Hi Micheal,</p>
<p>Do you know that ntext data type can’t do concatenation. To overcome this problem, we can use UPDATETEXT.<br />
The following are the example of using UPDATETEXT.</p>
<pre class="brush: sql; title: ; notranslate">
DECLARE @ptrval binary(16)
Declare @strComments nvarchar(4000)

SET @strComments = 'comments'

SELECT @ptrval = TEXTPTR(rd.Comment)
FROM vyRequisitionDetails rd
WHERE rd.RequisitionID = 'REQPhyuHT02012005-Delhi'

UPDATETEXT vyRequisitionDetails.Comment @ptrval NULL 0 @strComments
</pre>
<p>Grace
<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://michaelsync.net/2006/07/04/sql-2k-tips-updatetext&#038;layout=standard&#038;show_faces=false&#038;width=450&#038;height=25&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px;"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://michaelsync.net/2006/07/04/sql-2k-tips-updatetext/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>EXEC &amp; EXEC sp_executesql</title>
		<link>http://michaelsync.net/2006/07/04/exec-exec-sp_executesql</link>
		<comments>http://michaelsync.net/2006/07/04/exec-exec-sp_executesql#comments</comments>
		<pubDate>Tue, 04 Jul 2006 10:56:08 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Microsoft SQL]]></category>

		<guid isPermaLink="false">http://michaelsync.net/2006/07/04/exec-exec-sp_executesql</guid>
		<description><![CDATA[EXEC and EXEC sp_executesql for Searching.. Cool.. isn&#8217;t it? But there are one limitation of using sql_executesql. As this statement accept the NVARCHAR which has only 4000 words capacity, the SQL string muct be less than 4000 words. :( But &#8230; <a href="http://michaelsync.net/2006/07/04/exec-exec-sp_executesql">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>EXEC and EXEC sp_executesql for Searching..</p>
<pre class="brush: sql; title: ; notranslate">
DECLARE @sql as nvarchar(100)
DECLARE @paraDOB datetime
SET @paraDOB = '1/1/1981'
SET @sql=N''
SET @sql=N'SELECT * FROM EmpMast'
SET @sql=@sql + ' WHERE DOB &amp;gt;= @paraDOB'
exec sp_executesql @sql,N'@paraDOB datetime',@paraDOB&lt;/code&gt;
</pre>
<p>Cool.. isn&#8217;t it?<br />
But there are one limitation of using sql_executesql. As this statement accept the NVARCHAR which has only 4000 words capacity, the SQL string muct be less than 4000 words. :(</p>
<p>But I got the solution to solve this problem. By using EXEC with VARCHAR variable is the solution for this problem.</p>
<p>Here is the example.</p>
<pre>
DECLARE @sql as varchar(100)
DECLARE @paraDOB datetime
SET @paraDOB = '1/1/1981'
SET @sql=''
SET @sql='SELECT * FROM EmpMast'
SET @sql=@sql + ' WHERE DOB &gt;= ''' + CONVERT(NVARCHAR,@paraDOB) + ''''
EXEC (@sql)      ---- Note: ( ) is important.
</pre>
<p>When we use sp_executesql, we can pass hidden parameter. sp_executesql’s performance is better than EXEC.</p>
<p>Note: some people used to pass all parameters if they are using sp_executesql statement. Actually, it is NOT necessary to pass all parameters. The parameters are only needed to be passed when the value of parameters are needed to get back.
<div class='kouguu_fb_like_button'><iframe src="http://www.facebook.com/plugins/like.php?href=http://michaelsync.net/2006/07/04/exec-exec-sp_executesql&#038;layout=standard&#038;show_faces=false&#038;width=450&#038;height=25&#038;action=like&#038;colorscheme=light&#038;" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px;"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://michaelsync.net/2006/07/04/exec-exec-sp_executesql/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

