<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>SQL Server blogs from beyondrelational.com</title><link>http://beyondrelational.com</link><description>beyondrelational.com is a SQL Server blogging site where a number of SQL Server bloggers write regularly about a number of SQL Server topics.</description><webMaster>beyondrelational</webMaster><language>en-us</language><image><url>http://beyondrelational.com/modules/23/groups/362/images/17021eb5-e554-4269-a990-37b1db2393c9thumbnail.jpg</url><title>beyondrelational.com</title><link>http://beyondrelational.com</link><width>50</width><height>50</height></image><copyright>Copyright © Beyondrelational.com</copyright><lastBuildDate>Sun, 28 Apr 2013 06:52:02 GMT</lastBuildDate><ttl>60</ttl><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/beyondrelationalmain" /><feedburner:info uri="beyondrelationalmain" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>beyondrelationalmain</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>The EXECUTE permission was denied on the object 'xp_sqlagent_enum_jobs', database 'mssqlsystemresource', schema 'sys' - SQL Server</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/hjg9oy_SDUg/the-execute-permission-was-denied-on-the-object-xpsqlagentenumjobs-database-mssqlsystemresource-schema-sys-sql-server.aspx</link><description>&lt;p&gt;Recently while working with one query to get schedule jobs status, i used xp_sqlagent_enum_jobs object which gives details of state values of all jobs in msdb database and this is undocumented object. But received an error while running following query for same,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;EXECUTE master.dbo.xp_sqlagent_enum_jobs 1,'sa';&lt;/pre&gt;

&lt;p&gt;&lt;font size="4"&gt;&lt;strong&gt;Error&lt;/strong&gt; : &lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font color="#ff0000"&gt;Msg 229, Level 14, State 5, Procedure xp_sqlagent_enum_jobs, Line 1 
      &lt;br /&gt;The EXECUTE permission was denied on the object 'xp_sqlagent_enum_jobs', database 'mssqlsystemresource', schema 'sys'.&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As per error, says it does not have execute permission in &lt;em&gt;&lt;strong&gt;mssqlsystemresource&lt;/strong&gt;&lt;/em&gt; database for &lt;em&gt;sys&lt;/em&gt; schema.&lt;/p&gt;

&lt;p&gt;&lt;font size="4"&gt;&lt;strong&gt;Solution&lt;/strong&gt; :&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;For the solution just need to assign execute permission on dbo.xp_sqlagent_enum_jobs in &lt;strong&gt;master&lt;/strong&gt; database to user under the query to be run. So following query needs to be run against &lt;strong&gt;master&lt;/strong&gt; database,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE master
GO
GRANT EXECUTE ON xp_sqlagent_enum_jobs TO test;&lt;/pre&gt;

&lt;p&gt;Hope this help you if you will receive such an error and you may enjoyed this post. &lt;/p&gt;

&lt;p&gt;You can read my some earlier posts,&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/19159/addingmodifying-files-and-filegroup-in-database-sql-server.aspx"&gt;Adding/Modifying files and filegroup in Database&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/19312/moving-table-or-indexes-on-another-filegroup-sql-server.aspx"&gt;Moving table or indexes on another filegroup&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stay tuned for further post!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hjg9oy_SDUg:VLJWjhxXgEI:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hjg9oy_SDUg:VLJWjhxXgEI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hjg9oy_SDUg:VLJWjhxXgEI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hjg9oy_SDUg:VLJWjhxXgEI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hjg9oy_SDUg:VLJWjhxXgEI:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/hjg9oy_SDUg" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/19339/the-execute-permission-was-denied-on-the-object-xpsqlagentenumjobs-database-mssqlsystemresource-schema-sys-sql-server.aspx</guid><pubDate>Tue, 09 Apr 2013 16:30:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/19339/the-execute-permission-was-denied-on-the-object-xpsqlagentenumjobs-database-mssqlsystemresource-schema-sys-sql-server.aspx</feedburner:origLink></item><item><title>Moving table or indexes on another filegroup - SQL Server</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/PopUYQxw46o/moving-table-or-indexes-on-another-filegroup-sql-server.aspx</link><description>&lt;p&gt;Because of data growth and performance issue we need to move tables or indexes to other filegroups. The purpose of moving tables or indexes to improve the database performance as it reduce I/O from single drive or single filegroup. We can create another filegroup and move the tables and indexes to new created filegroups, then it will spit the I/O to two different filegroups. This way it will improve performance.&lt;/p&gt;  &lt;p&gt;When we need to move the tables or indexes to other filegroup? We should move those table need to move which are having more rows or heavily in size, Also need to move if those tables data are frequently updated. Here i would like to show the demo for the same. Let us see how can we move tables/indexes to other filegroup.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;-- First we are creating database  
-- Main primary file on Primary filegroup 
-- Secondary files on secondary filegroup. 
-- Log files on different file group. 
CREATE DATABASE filegroupdb 
ON PRIMARY 
	( name = filegroupdb_data, 
	filename = 'C:\FileGroupDB_Data.mdf', 
	size = 4 mb, 
	maxsize = 5 mb, 
	filegrowth = 1 mb ), 
filegroup secfilegroup 
	( name = filegroupdb_data_1, 
	filename = 'C:\FileGroupDB_Data_1.ndf', 
	size = 2 mb, 
	maxsize = 5 mb, 
	filegrowth = 1 mb ) 
log ON 
	( name = filegroupdb_log, 
	filename = 'C:\FileGroupDB_Log.ldf', 
	size = 2 mb, 
	maxsize = 5 mb, 
	filegrowth = 1 mb ) 

GO &lt;/pre&gt;

&lt;p&gt;After creating database we will create a new table on Primary filegroup. If you not mentioned filegroup name then it will be created on default filegroup. Let us create it.&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE filegroupdb 
GO 

-- Creating table on Primary filegroup 
IF( Object_id('tblFileGroup', 'u') &amp;gt; 0 ) 
  DROP TABLE tblfilegroup 
GO 

CREATE TABLE tblfilegroup 
  ( 
     objectid   INT NOT NULL PRIMARY KEY, 
     objectname VARCHAR(100), 
     createdate DATETIME 
  ) 
ON [PRIMARY] 

GO&lt;/pre&gt;

&lt;p&gt;Table is created and now we look the property of table where it is created,&lt;/p&gt;
&lt;strong&gt;&lt;font color="#0000ff"&gt;SP_HELP&lt;/font&gt; tblFileGroup&lt;/strong&gt; 

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=0d2b1b146593498fb2d1231aaf9ed097&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MovingTable_1" border="0" alt="MovingTable_1" src="http://media.beyondrelational.com/images.ashx?id=86a61f7148fc4db988a3b4d9cbe8e60c&amp;amp;w=-1&amp;amp;h=-1" width="644" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we coming on the point which is tables/indexes actually will be moved. There are two way through we can move the tables and indexes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#1. &lt;em&gt;By moving clustered index&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using this way we just need to move clustered index and tables and all indexes will be moved to different filegroup. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;How can with #1 way?&lt;/em&gt;&lt;/p&gt;

&lt;pre class="brush: sql; toolbar: false"&gt;-- Defining dropping constraint with move
ALTER TABLE tblFileGroup
DROP CONSTRAINT PK__tblFileG__9A619291029E5EB6 WITH (MOVE TO SecFileGroup)
GO

-- Adding constraint
ALTER TABLE tblFileGroup 
ADD CONSTRAINT PK__tblFileG__9A619291029E5EB6 PRIMARY KEY(ObjectId)
GO&lt;/pre&gt;

&lt;p&gt;Let us check again the properties of tables as successfully moved or not.&lt;/p&gt;
&lt;strong&gt;&lt;font color="#0000ff"&gt;SP_HELP&lt;/font&gt; tblFileGroup&lt;/strong&gt; 

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=785a66cef5ce44f1ad1858db83d3b6ec&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MovingTable_2" border="0" alt="MovingTable_2" src="http://media.beyondrelational.com/images.ashx?id=f0cbd7dc896b4984a43c755c104a635b&amp;amp;w=-1&amp;amp;h=-1" width="650" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#2. &lt;em&gt;Recreate a clustered index with drop existing&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We just need to recreate a tables clustered index with drop existing clustered index on that.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;How can with #2 way?&lt;/em&gt;&lt;/p&gt;

&lt;pre class="brush: sql"&gt;CREATE UNIQUE CLUSTERED INDEX PK__tblFileG__9A619291029E5EB6
ON tblFileGroup(ObjectId)
   WITH DROP_EXISTING
ON SecFileGroup

GO&lt;/pre&gt;

&lt;p&gt;You also worked with moving tables/indexes to other location , Share your ideas here!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=PopUYQxw46o:hvpjkaWWc0o:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=PopUYQxw46o:hvpjkaWWc0o:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=PopUYQxw46o:hvpjkaWWc0o:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=PopUYQxw46o:hvpjkaWWc0o:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=PopUYQxw46o:hvpjkaWWc0o:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/PopUYQxw46o" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/19312/moving-table-or-indexes-on-another-filegroup-sql-server.aspx</guid><pubDate>Thu, 04 Apr 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/19312/moving-table-or-indexes-on-another-filegroup-sql-server.aspx</feedburner:origLink></item><item><title>Conditional aggregation - SUM Vs COUNT</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/_dxAEdhRM6M/conditional-aggregation-sum-vs-count.aspx</link><description>&lt;P&gt;You can do conditional aggregation like SUM(CASE WHEN .. THEN 1 ELSE 0 END),....etc to find a count for a particular match. This type of conditions are useful when you want to write a CROSS-TAB/PIVOT Query. You can also make use of COUNT(CASE WHEN .. THEN 1 END). One of the developers told me that he used the same type of queries but the count did not seem to be correct. I asked him to show the code. His code has the following pattern&lt;/P&gt;&lt;PRE class=brush:sql&gt;COUNT(CASE WHEN .. THEN 1 ELSE 0 END)&lt;/PRE&gt;
&lt;P&gt;I immediately pointed out to him that the above condition is equivalent to COUNT(*) because COUNT will count everything other than NULL. In the above expression both 1 and 0 are counted. So either COUNT should be replaced with SUM or 0 should be NULL.&lt;/P&gt;
&lt;P&gt;But for these types are expressions I would like to use SUM instead of COUNT.&amp;nbsp; There are atleast two reasons I know&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1 SUM can be used to COUNT as well as to SUM the values. See the below examples&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;SUM(CASE WHEN gender='M' THEN 1 ELSE 0 END) as male_count,
SUM(CASE WHEN year(trans_date)=2012 THEN trans_amount ELSE 0 END) as total_2012
&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;The first expression COUNTs how many males in the recordset and second expression SUMs the values of the column named trans_amout for the year 2012.&lt;/P&gt;
&lt;P&gt;COUNT can be used only for COUNTing as below&lt;/P&gt;&lt;PRE class=brush:sql&gt;COUNT(CASE WHEN gender='M' THEN 1 END) as male_count
&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;&lt;STRONG&gt;2 NULL warning&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Using SUM will almost avoid NULL warning. In the first expression the derived values are always 1 and 0 so you will never get any warnings on NULL. In the second example, if the column&amp;nbsp;trans_amount is a NOT NULL column, you will never get a NULL&amp;nbsp;warning but if it is NULLable column and if there are some NULL values for the transaction year 2012, you will get a NULL warning. The NULL warning is as below&lt;/P&gt;&lt;STRONG&gt;&lt;EM&gt;Warning: Null value is eliminated by an aggregate or other SET operation.&lt;/EM&gt;&lt;/STRONG&gt; 
&lt;P&gt;But using COUNT will most likely result to NULL warning until there are no rows with gender&amp;lt;&amp;gt;'M'. &lt;/P&gt;
&lt;P&gt;The NULL warning depends on the data.&amp;nbsp;So use conditional aggregations cleverly. &lt;/P&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=_dxAEdhRM6M:pV1h41Mmmdc:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=_dxAEdhRM6M:pV1h41Mmmdc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=_dxAEdhRM6M:pV1h41Mmmdc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=_dxAEdhRM6M:pV1h41Mmmdc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=_dxAEdhRM6M:pV1h41Mmmdc:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/_dxAEdhRM6M" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/70/posts/19240/conditional-aggregation-sum-vs-count.aspx</guid><pubDate>Tue, 26 Mar 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/70/posts/19240/conditional-aggregation-sum-vs-count.aspx</feedburner:origLink></item><item><title>Failed to acquire connection. Connection may not be configured correctly or you may not have the right permissions on this connection.-SQL Server SSIS</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/kOFQzxSY3nc/failed-to-acquire-connection-connection-may-not-be-configured-correctly-or-you-may-not-have-the-right-permissions-on-this-connec.aspx</link><description>&lt;p&gt;This week, I resolved one issue which I received continuously which is noting but exactly displayed in post title.&amp;#160; The issue occurred&amp;#160; when I ran ssis package with batch file or scheduled job and same error message raised. &lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;em&gt;Source: Start Execute SQL Task        &lt;br /&gt;&amp;#160;&amp;#160; Description: Failed to acquire connection &amp;quot;&amp;lt;Connection Name&amp;gt;&amp;quot;. Connection may not be configured correctly or you may not have the right permissions on this connection.&lt;/em&gt;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;As per title, it seems an issue with connection of server configured in ssis package. I thought same because this type of error comes when server is not connecting or it does not have proper and rights to connect. First I checked all servers connection and tried to resolved it, but not succeed.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Please note I received this error only while running ssis package with scheduled job or batch file, But it was working fine while running ssis package directly.&lt;/strong&gt; It means it is not an issue in ssis package but it is with batch file or schedule job. After tried I visited one &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/912d2b13-34a1-4f5d-ad8b-a4ca344b2ee1/" target="_blank"&gt;conversion&lt;/a&gt; which says i t may be issue with 32 bit/64 bit mode. And here I configured ssis package with schedule job and batch file with servers having operating system 64 bit. &lt;/p&gt;  &lt;p&gt;After changing ssis package with schedule jobs and batch file with 32 bit, it works fine for me. Let me share,&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;With Batch file&lt;/font&gt;&lt;/strong&gt;,&lt;/p&gt;  &lt;p&gt;I changed path of &lt;strong&gt;dtexec.exe&lt;/strong&gt; from &amp;lt;drive&amp;gt;:\Program Files\Microsoft SQL Server\100\DTS\Binn to &amp;lt;drive&amp;gt;:\Program Files(x86)\Microsoft SQL Server\100\DTS\Binn like following batch file content,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;&amp;quot;C:\Program Files (x86)\Microsoft SQL Server\100\dts\Binn\dtexec.exe&amp;quot; /FILE  &amp;quot;C:\SSIS\SSISTest\bin\testing.dtsx&amp;quot; /MAXCONCURRENT &amp;quot; -1 &amp;quot; /CHECKPOINTING OFF  /REPORTING EWCDI &lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;With Scheduled job&lt;/font&gt;&lt;/strong&gt;,&lt;/p&gt;

&lt;p&gt;I am sharing one screen shot of schedule job step configuration of ssis package,&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=b8603736eb8b477485aa5ddb5982e6b6&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ssiserror" border="0" alt="ssiserror" src="http://media.beyondrelational.com/images.ashx?id=6ab4ca6fd4604f8dacf841dc16e603a5&amp;amp;w=-1&amp;amp;h=-1" width="554" height="416" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Day after this changed, I always see this package succeed. I am leaving one discussion open here “why it was failing with 64 bit mode run? &lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=kOFQzxSY3nc:oJPGCo3uemQ:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=kOFQzxSY3nc:oJPGCo3uemQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=kOFQzxSY3nc:oJPGCo3uemQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=kOFQzxSY3nc:oJPGCo3uemQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=kOFQzxSY3nc:oJPGCo3uemQ:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/kOFQzxSY3nc" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/19188/failed-to-acquire-connection-connection-may-not-be-configured-correctly-or-you-may-not-have-the-right-permissions-on-this-connec.aspx</guid><pubDate>Thu, 21 Mar 2013 12:04:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/19188/failed-to-acquire-connection-connection-may-not-be-configured-correctly-or-you-may-not-have-the-right-permissions-on-this-connec.aspx</feedburner:origLink></item><item><title>Handling multiple resultsets returned from Stored Procedure</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/MdVkd15V1EU/handling-multiple-resultsets-returned-from-stored-procedure.aspx</link><description>One of my friends asked me if it is possible to load multiple resultsets returned from a stored procedure into a temporary table for some analysis purpose. The answer is "It depends". If all the resultsets return same number of columns then it is possible. Consider the following stored procedure&lt;PRE class=brush:sql&gt;create procedure proc_testing
as
select 345 as number
select 52345 as number
select 1200 as number
&lt;/PRE&gt;&lt;BR&gt;Executing this procedure will&amp;nbsp;give three resultsets&amp;nbsp; Now create a temporary table&lt;PRE class=brush:sql&gt;create table #temp(number int)&lt;/PRE&gt;Add data to this table by executing the stored procedure &lt;PRE class=brush:sql&gt;insert into #temp(number) 
exec proc_testing
&lt;/PRE&gt;&lt;BR&gt;Check the result from the table &lt;PRE class=brush:sql&gt;select * from #temp
&lt;/PRE&gt;&lt;BR&gt;The result is &lt;PRE class=brush:sql&gt;number
-----------
345
52345
1200&lt;/PRE&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: Currently it is not possible to identify a specific resultset from the stored procedure.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MdVkd15V1EU:zEH5ZpZIvc4:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MdVkd15V1EU:zEH5ZpZIvc4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MdVkd15V1EU:zEH5ZpZIvc4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MdVkd15V1EU:zEH5ZpZIvc4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MdVkd15V1EU:zEH5ZpZIvc4:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/MdVkd15V1EU" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/70/posts/19179/handling-multiple-resultsets-returned-from-stored-procedure.aspx</guid><pubDate>Wed, 20 Mar 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/70/posts/19179/handling-multiple-resultsets-returned-from-stored-procedure.aspx</feedburner:origLink></item><item><title>Adding/Modifying files and filegroup in Database - SQL Server</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/FkAVSwGNIdc/addingmodifying-files-and-filegroup-in-database-sql-server.aspx</link><description>&lt;p&gt;You all know about the database file structure as whenever we created databases without specifying file location and filegroups , they will be created in default path and default filegroup. Here i have tried to created a new database without defining any options, look the file structure on the default location and the default group.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;CREATE DATABASE FILEGROUPDB
GO

SP_HELPDB FileGroupDB
GO&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=5d80042e6b044e4298cd635e06768a9e&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="AddingFile_1" border="0" alt="AddingFile_1" src="http://media.beyondrelational.com/images.ashx?id=685fc04fb41f45c5b0f7a551505a66a7&amp;amp;w=-1&amp;amp;h=-1" width="601" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Click on image to enlarge)&lt;/p&gt;

&lt;p&gt;We can change the default filegroup with following script.&lt;/p&gt;

&lt;pre class="brush: sql"&gt;ALTER DATABASE AdventureWorks2008R2 
MODIFY FILEGROUP [PRIMARY] DEFAULT; 
GO&lt;/pre&gt;

&lt;p&gt;As a best perspective for the database Architecture some frequently updated or used tables should be on different filegroup and the database secondary and log files also be one different filegroup. TempDB data and log files should have alone disk and filegroup as well. &lt;/p&gt;

&lt;p&gt;Let us we go ahead with some of activities as how can we can create a new filegroup, how can wee add the new secondary files to that filegroup. We will also look for the modifying the database file and changing the location.&amp;nbsp; First capture the above image of the database file structure before doing any activities with database files. Please go with details explained by comments in the script below and then we will compare the database file structure with original one.&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE MASTER 
GO

-- Adding a new filegroup to database 
ALTER DATABASE FileGroupDB 
ADD FILEGROUP NewFileGroup; 
GO

--Adding a new seconday and log files to a database to above created filegroup 
ALTER DATABASE FileGroupDB 
ADD FILE 
( 
    -- New secondary files added here 
    NAME = FileGroupDB_Data_1, 
    FILENAME = 'C:\FileGroupDB_Data_1.ndf', 
    SIZE = 15 MB, 
    MAXSIZE = 100 MB, 
    FILEGROWTH = 5 MB 
), 
( 
    -- New log file added here 
    NAME = FileGroupDB_Log_1, 
    FILENAME = 'C:\FileGroupDB_Log_1.ldf', 
    SIZE = 5 MB, 
    MAXSIZE = 100 MB, 
    FILEGROWTH = 5 MB 
) 
TO FILEGROUP NewFileGroup; -- Defining filegroup name here 
GO

-- Modifying size of the file 
ALTER DATABASE FileGroupDB 
MODIFY FILE  
( 
-- Changing log file size here 
NAME = FileGroupDB_Log, 
SIZE = 20 MB 
)

-- Moving log file to another location 
ALTER DATABASE FileGroupDB 
MODIFY FILE 
( 
NAME = FILEGROUPDB_log, -- Moving first log file to new location here 
FILENAME = 'C:\FileGroupDB_Log.ldf' 
) 
GO&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=8ef6df010cfb405da1c4e7e12512a9ff&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="AddingFile_2" border="0" alt="AddingFile_2" src="http://media.beyondrelational.com/images.ashx?id=21bd593d02dd4c939d7137eaba101369&amp;amp;w=-1&amp;amp;h=-1" width="618" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Click on image to enlarge)&lt;/p&gt;

&lt;p&gt;After running last script you will notified by following message, 
  &lt;br&gt;&lt;font color="#0000ff"&gt;"The file "FILEGROUPDB_log" has been modified in the system catalogue. The new path will be used the next time the database is started. &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;It will use the new file location when SQL Service will be restarted. We can have another option is taking database offline and use same scripts written above and again database needs to back online which does not need to restart database service.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=FkAVSwGNIdc:S7ILRU40NFg:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=FkAVSwGNIdc:S7ILRU40NFg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=FkAVSwGNIdc:S7ILRU40NFg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=FkAVSwGNIdc:S7ILRU40NFg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=FkAVSwGNIdc:S7ILRU40NFg:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/FkAVSwGNIdc" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/19159/addingmodifying-files-and-filegroup-in-database-sql-server.aspx</guid><pubDate>Sat, 16 Mar 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/19159/addingmodifying-files-and-filegroup-in-database-sql-server.aspx</feedburner:origLink></item><item><title>BCP - Changing the default column terminator</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/MWhZ3jyfrzg/bcp-changing-the-default-column-terminator.aspx</link><description>&lt;P&gt;&lt;STRONG&gt;BCP&lt;/STRONG&gt; is one of the fastest methods to export data to various formats like csv,txt,etc and doing this in a command mode is faster than doing it via &lt;STRONG&gt;SSMS&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;Let us create this simple table&lt;/P&gt;&lt;PRE class=brush:sql&gt;create table test(id int, name varchar(50))

insert into test(id,name)
select 1,'Sankar' union all
select 2,'Kumar' union all
select 3,'Nilesh' 

&lt;/PRE&gt;
&lt;P&gt;Now open the command processor and run this code (Replace dbname,Servername, username and password with actual values)&lt;/P&gt;&lt;PRE class=brush:sql&gt;BCP dbname..test out "C:\test.csv" -c -S Servername -U username -P Password&lt;/PRE&gt;
&lt;P&gt;The data from the table test is now available in the file test.csv. When you open the file, you can notice that the column terminator is a tab. If you want to change it to a comma(,) or a pipe sysmbol (|), or any other character as terminatiors use the option -t followed by terminator. So the following code uses comma as the column terminator&lt;/P&gt;&lt;PRE class=brush:sql&gt;BCP test..test out "C:\test.csv" -c -t, -S Servername -U username -P Password&lt;/PRE&gt;
&lt;P&gt;If you want pipe symbol as a column terminator, use the following code&lt;/P&gt;&lt;PRE class=brush:sql&gt;BCP test..test out "C:\test.csv" -c -t"|" -S Servername -U username -P Password&lt;/PRE&gt;
&lt;P&gt;Note that only a comma can be specified without double quotes. All other terminators should be specified within double quotes.&lt;/P&gt;
&lt;P&gt;So use the column terminator option -t to change the column terminator as you wish&lt;BR&gt;&lt;/P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWhZ3jyfrzg:kFi5IL2BkU8:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWhZ3jyfrzg:kFi5IL2BkU8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWhZ3jyfrzg:kFi5IL2BkU8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWhZ3jyfrzg:kFi5IL2BkU8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWhZ3jyfrzg:kFi5IL2BkU8:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/MWhZ3jyfrzg" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/70/posts/19120/bcp-changing-the-default-column-terminator.aspx</guid><pubDate>Fri, 08 Mar 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/70/posts/19120/bcp-changing-the-default-column-terminator.aspx</feedburner:origLink></item><item><title>How to increase the number of characters retrieved from the server for XML data-SQL Server</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/au7KBNC4CKk/how-to-increase-the-number-of-characters-retrieved-from-the-server-for-xml-data-sql-server.aspx</link><description>&lt;p&gt;You may worked with xml and you may aware of title mentioned in this post. Today when I was working to collect information from one table which having xml column, I was trying to open xml data result set from query analyzer with new query window. For some of xml data result set it raised an error below while opening with new window ,&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;Unable to show XML. The following error happened:&amp;nbsp; There is an unclosed literal string. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=6300f74504144961885bee987d17e26f&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="xmlresultError" border="0" alt="xmlresultError" src="http://media.beyondrelational.com/images.ashx?id=403ba3866d11476581bbc856e1179edd&amp;amp;w=-1&amp;amp;h=-1" width="542" height="145"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This is just an error I faced for some xml data which are &lt;u&gt;&lt;strong&gt;lengthy in size&lt;/strong&gt;&lt;/u&gt;. But error is showing solution too &lt;font color="#000000"&gt;&lt;em&gt;“One solution is to increase the number of characters retrieved from the server for XML data. To change this setting, on the Tools menu, click Options”&lt;/em&gt;&lt;/font&gt;. Let follow toward it and go ahead the step suggested, please see below snapshot which is showing the option where we can change the setting suggested,&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Tools –&amp;gt; Options&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=5f248791636a40d3916286a22e407c67&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="xmlresulterror_3" border="0" alt="xmlresulterror_3" src="http://media.beyondrelational.com/images.ashx?id=31f3987ef47b417bb7c26ed4733acc1f&amp;amp;w=-1&amp;amp;h=-1" width="541" height="317"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nothing to say other than screen shot above. I know this is common post but I shared it with you because I never faced this issue earlier and also did not aware about this setting. Let us share here if have this in your mind earlier.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=au7KBNC4CKk:41Rt4NJCNzc:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=au7KBNC4CKk:41Rt4NJCNzc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=au7KBNC4CKk:41Rt4NJCNzc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=au7KBNC4CKk:41Rt4NJCNzc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=au7KBNC4CKk:41Rt4NJCNzc:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/au7KBNC4CKk" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/19110/how-to-increase-the-number-of-characters-retrieved-from-the-server-for-xml-data-sql-server.aspx</guid><pubDate>Mon, 04 Mar 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/19110/how-to-increase-the-number-of-characters-retrieved-from-the-server-for-xml-data-sql-server.aspx</feedburner:origLink></item><item><title>Skip distributor agent error in sql server transactional replication - How to</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/SMYNqCt0Gxs/skip-distributor-agent-error-in-sql-server-transactional-replication-how-to.aspx</link><description>&lt;p&gt;A while before few weeks, I discussed about an error of replication “&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18695/the-row-was-not-found-at-the-subscriber-when-applying-the-replicated-command-replication-error-in-sq.aspx" target="_blank"&gt;&lt;font size="3"&gt;The row was not found at the Subscriber when applying the replicated command&lt;/font&gt;&lt;/a&gt;”.&amp;nbsp; We had a tricks to get discrepancies for error table and resolved issue. Let me put another method (Actually patch) to come out from same error which is very interesting. Before to move this method, Please read some my posts related to replication which you may like,&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18637/replication-components-are-not-installed-on-this-server-error-while-adding-subscriber-in-replication.aspx" target="_blank"&gt;Replication components are not installed on this server-Error while adding subscriber in replication&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18664/replicated-transactions-are-waiting-for-next-log-backup-or-for-mirroring-partner-to-catch-up-issue-i.aspx" target="_blank"&gt;Replicated transactions are waiting for next Log backup or for mirroring partner to catch up-Issue in SQL Server Replication&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Now going to move ahead , here I am talking about the solution for the above highlighted error while is “&lt;strong&gt;&lt;em&gt;Skip error in sql server transactional replication&lt;/em&gt;, How to ? &lt;/strong&gt;”. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="5"&gt;Raise a problem&lt;/font&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;We will consider the same objects created&amp;nbsp; and same scenario for transactional replication in &lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18695/the-row-was-not-found-at-the-subscriber-when-applying-the-replicated-command-replication-error-in-sq.aspx" target="_blank"&gt;&lt;font size="4"&gt;this post&lt;/font&gt;&lt;/a&gt;. Let us check the data of ready made tables,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;SELECT * 
FROM   test.dbo.sample1 (nolock) 

SELECT * 
FROM   test1.dbo.sample1 (nolock) &lt;/pre&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=6582ee9f6fbc48ecbb6891944e6ade05&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ReplSkipError" border="0" alt="ReplSkipError" src="http://media.beyondrelational.com/images.ashx?id=05358b7d416b44f697c57ee2d94c709f&amp;amp;w=-1&amp;amp;h=-1" width="483" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have same records in both tables at publisher and subscriber side. Now it is time to create discrepancies using following script,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;-- Deleting one record from table in subscriber database 
DELETE FROM test1.dbo.sample1 
WHERE  id = 2 

-- Updating same record from table in publisher database 
UPDATE test.dbo.sample1 
SET    name = 'test5' 
WHERE  id = 2 

-- Inserting new record in table in publisher database 
INSERT test.dbo.sample1 
SELECT 4, 
       'test4' &lt;/pre&gt;

&lt;p&gt;Monitoring replication after above script ran, &lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=6023b33a249d4401ad38f7ec112273c7&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ReplSkipError2" border="0" alt="ReplSkipError2" src="http://media.beyondrelational.com/images.ashx?id=53092db2114648ddaadda624a6cda617&amp;amp;w=-1&amp;amp;h=-1" width="487" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And viewing table’s data again from publisher and subscriber after an error,&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=38e2032169204e4e8ffe3b63d3cb40b7&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ReplSkipError3" border="0" alt="ReplSkipError3" src="http://media.beyondrelational.com/images.ashx?id=45b0ef74ea9749298a4775a1600620ff&amp;amp;w=-1&amp;amp;h=-1" width="483" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see nothing happened at subscriber because of an error occurred for one missing row.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;Solution&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are about to skip this error where all replication commands stuck, So &lt;em&gt;&lt;font size="3"&gt;&lt;a href="http://technet.microsoft.com/en-us/library/ms188764.aspx" target="_blank"&gt;sp_setsubscriptionxactseqno&lt;/a&gt;&lt;/font&gt;&lt;/em&gt; system stored procedure help us which is used to troubleshooting to specify the log sequence number (LSN) of the next transaction to be applied by the Distribution Agent at the Subscriber. So let us first get sequence number of an error which we have from the replication monitor. We can also use following script to get all transactional replication errors and executed in distributor server in distribution database,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE distribution 
GO

DECLARE @PublisherServer  VARCHAR(50), 
        @PublicationDB    VARCHAR(50), 
        @SubscriberServer VARCHAR(50), 
        @SubscriberDB     VARCHAR(50), 
        @PublicationName  VARCHAR(50) 

SET @PublisherServer = '&amp;lt;Publisher&amp;gt;' 
SET @PublicationDB = 'test' 
SET @SubscriberServer = '&amp;lt;Subscriber&amp;gt;' 
SET @SubscriberDB = 'test1' 
SET @PublicationName = 'testpub' 

EXEC Sp_helpsubscriptionerrors 
  @PublisherServer, 
  @PublicationDB, 
  @PublicationName, 
  @SubscriberServer, 
  @SubscriberDB 

GO &lt;/pre&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=9971e39c51144a90b5851253909f1f97&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ReplSkipError4" border="0" alt="ReplSkipError4" src="http://media.beyondrelational.com/images.ashx?id=5867ae6ca98e464eac2a85c2afdea130&amp;amp;w=-1&amp;amp;h=-1" width="485" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Click on image to enlarge)&lt;/p&gt;

&lt;p&gt;Please get a top sequence number of an error from where all transaction commands stuck and run following script at subscriber side,&lt;/p&gt;



&lt;pre class="brush: sql"&gt;USE test1 
GO

DECLARE @PublisherServer VARCHAR(50), 
        @PublicationDB   VARCHAR(50), 
        @PublicationName VARCHAR(50) 

SET @PublisherServer = '&amp;lt;Publisher&amp;gt;'
SET @PublicationDB = 'test' 
SET @PublicationName = 'testpub' 

EXEC Sp_setsubscriptionxactseqno 
  @PublisherServer, 
  @PublicationDB, 
  @PublicationName, 
  0x00000022000000C1000400000000 

GO&lt;/pre&gt;
&lt;a href="http://media.beyondrelational.com/images.ashx?id=f6693fc9180841028586df23e6acc971&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ReplSkipError5" border="0" alt="ReplSkipError5" src="http://media.beyondrelational.com/images.ashx?id=086dc62a24a34df38ca969012cb9ba23&amp;amp;w=-1&amp;amp;h=-1" width="488" height="87"&gt;&lt;/a&gt;&amp;nbsp; &lt;br&gt;Finally running above script at subscriber database, this error skipped and all remaining and pending commands were applied which we can see the data of both tables from publisher and subscriber database,



&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=8b8dad730ef1429bb139856a13a65e69&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ReplSkipError6" border="0" alt="ReplSkipError6" src="http://media.beyondrelational.com/images.ashx?id=ee06ce4e476f4c37b10e3d78f5eafd4a&amp;amp;w=-1&amp;amp;h=-1" width="486" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is just my experience&amp;nbsp; which I am sharing with you. It is recommending to find a route of this error and solve it. &lt;/p&gt;

&lt;p&gt;Did you received such error and you skipped any? Please share your thoughts! &lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=SMYNqCt0Gxs:XHzSfbM7Hlw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=SMYNqCt0Gxs:XHzSfbM7Hlw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=SMYNqCt0Gxs:XHzSfbM7Hlw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=SMYNqCt0Gxs:XHzSfbM7Hlw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=SMYNqCt0Gxs:XHzSfbM7Hlw:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/SMYNqCt0Gxs" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/19093/skip-distributor-agent-error-in-sql-server-transactional-replication-how-to.aspx</guid><pubDate>Wed, 27 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/19093/skip-distributor-agent-error-in-sql-server-transactional-replication-how-to.aspx</feedburner:origLink></item><item><title>Import data - solving data convertion and truncation error</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/D14HRseBSp8/import-data-solving-data-convertion-and-truncation-error.aspx</link><description>&lt;P&gt;Often developers use &lt;STRONG&gt;Import wizard&lt;/STRONG&gt; from &lt;STRONG&gt;SSMS&lt;/STRONG&gt; or &lt;STRONG&gt;SSIS&lt;/STRONG&gt; to import data from a text file into a table. You may or may not import it successfully based on the nature of the data.&lt;/P&gt;
&lt;P&gt;Create a text file named test.txt with the following data&lt;/P&gt;
&lt;P&gt;id|name|address&lt;BR&gt;1|ramesh|12th road,chennai&lt;BR&gt;2|nilesh|this is testing address and it has more than fifty characters: 4th cross street, adyar, chennai, tamil nadu, India&lt;/P&gt;
&lt;P&gt;Now using an import wizard from &lt;STRONG&gt;SSMS&lt;/STRONG&gt;, try to import this file to a table.&lt;/P&gt;
&lt;P&gt;Right click on database--&amp;gt;&lt;STRONG&gt;Import data&lt;BR&gt;&lt;/STRONG&gt;Choose &lt;STRONG&gt;Data source&lt;/STRONG&gt; as &lt;STRONG&gt;Flat file source&lt;/STRONG&gt;, &lt;STRONG&gt;browse&lt;/STRONG&gt; the file, Under the &lt;STRONG&gt;Data source&lt;/STRONG&gt; tab, choose the &lt;STRONG&gt;columns&lt;/STRONG&gt; and make sure that &lt;STRONG&gt;Row delimiter&lt;/STRONG&gt; is {CR}{LF} and &lt;STRONG&gt;column delimiter&lt;/STRONG&gt; as Vertical Bar {|}, click &lt;STRONG&gt;next&lt;/STRONG&gt; and choose the &lt;STRONG&gt;destination&lt;/STRONG&gt; as &lt;STRONG&gt;SQL Server native client 11.0&lt;/STRONG&gt;, choose the relevant &lt;STRONG&gt;authentication mode&lt;/STRONG&gt; and a &lt;STRONG&gt;database&lt;/STRONG&gt;, click &lt;STRONG&gt;next&lt;/STRONG&gt; and at last click &lt;STRONG&gt;Finish&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;In the step named &lt;STRONG&gt;Executing&lt;/STRONG&gt;, the status shows as &lt;STRONG&gt;error&lt;/STRONG&gt;. Click on the error, it will pop-up a new window with the error message&lt;/P&gt;
&lt;P&gt;&lt;SPAN lang=EN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;- Executing (Error)&lt;/FONT&gt;&lt;/P&gt;
&lt;DIR&gt;
&lt;DIR&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Messages&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "address" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".&lt;BR&gt;(SQL Server Import and Export Wizard)&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Error 0xc020902a: Data Flow Task 1: The "Source - test_txt.Outputs[Flat File Source Output].Columns[address]" failed because truncation occurred, and the truncation row disposition on "Source - test_txt.Outputs[Flat File Source Output].Columns[address]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.&lt;BR&gt;(SQL Server Import and Export Wizard)&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "C:\test.txt" on data row 3.&lt;BR&gt;(SQL Server Import and Export Wizard)&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Source - test_txt returned error code 0xC0202092. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.&lt;BR&gt;(SQL Server Import and Export Wizard)&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;B&gt;&lt;/DIR&gt;&lt;/DIR&gt;
&lt;P&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;BR&gt;So where is the problem?&lt;/P&gt;
&lt;P&gt;Now go back to the initial step of this wizard (Choosing Data Source). Under &lt;STRONG&gt;Data Source&lt;/STRONG&gt; click on &lt;STRONG&gt;Advanced&lt;/STRONG&gt;, choose the column &lt;STRONG&gt;address&lt;/STRONG&gt;. The &lt;STRONG&gt;output column width is 50&lt;/STRONG&gt; (by default all varchar columns will have width of 50), change it to &lt;STRONG&gt;100&lt;/STRONG&gt; and do the same process. All data will get imported succesfully.&lt;/P&gt;
&lt;P&gt;So kwwp this in mind while using a import wizard or SSIS and increase the width from &lt;STRONG&gt;default value of 50&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=D14HRseBSp8:VMfr2wYKSrw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=D14HRseBSp8:VMfr2wYKSrw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=D14HRseBSp8:VMfr2wYKSrw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=D14HRseBSp8:VMfr2wYKSrw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=D14HRseBSp8:VMfr2wYKSrw:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/D14HRseBSp8" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/70/posts/19094/import-data-solving-data-convertion-and-truncation-error.aspx</guid><pubDate>Wed, 27 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/70/posts/19094/import-data-solving-data-convertion-and-truncation-error.aspx</feedburner:origLink></item><item><title>Print screen for Remote Desktop</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/-jgRvEHvzZ4/print-screen-for-remote-desktop.aspx</link><description>Earlier on Beyondrelational I read a tip, for the same topic.
combination of keys Shift + Print screen, allows us to take screen shot of Remote Desktop.
But recently I faced problem using these keys. It allowed taking print screen only once. Every other time, it comes up with the first screen shot i took.
Solution I found was : Start menu -&gt; Accessories -&gt; Accessibility -&gt; On-Screen Key board.
On the keyboard that pops up, use the keys : alt + printscreen + enter.
This has solved my issue, I can take as many screen shots as I want for Remote desktop&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=-jgRvEHvzZ4:AiG3Wriz5fo:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=-jgRvEHvzZ4:AiG3Wriz5fo:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=-jgRvEHvzZ4:AiG3Wriz5fo:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=-jgRvEHvzZ4:AiG3Wriz5fo:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=-jgRvEHvzZ4:AiG3Wriz5fo:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/-jgRvEHvzZ4" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/1/justlearned/tips/19033/print-screen-for-remote-desktop.aspx</guid><pubDate>Wed, 20 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/1/justlearned/tips/19033/print-screen-for-remote-desktop.aspx</feedburner:origLink></item><item><title>Merge statement with TOP clause - SQL Server</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/9XeHs4N_OFY/merge-statement-with-top-clause-sql-server.aspx</link><description>&lt;p&gt;A week ago, I posted for &lt;font size="4"&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/posts/10095/top-clause-with-insert-update-and-delete-statements-in-sql-server-2005.aspx" target="_blank"&gt;Insert, Update and Delete statement with TOP clause&lt;/a&gt;&lt;/font&gt; and &lt;a href="http://beyondrelational.com/modules/2/blogs/88/posts/10120/merge-statement-a-new-tsql-feature-of-sql-server-2008.aspx" target="_blank"&gt;&lt;font size="4"&gt;Merge statement&lt;/font&gt;&lt;/a&gt; as individual post. If you not read those posts then read it before to move next. In this posts I used TOP clause with DML operations and Merge statement but both are individual posts. Let me put these two posts together here and create new one. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;What is it ?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;It is nothing but the form of two individual posts and it is &lt;em&gt;&lt;u&gt;Merge statement with TOP clause&lt;/u&gt;&lt;/em&gt;.&amp;nbsp; I never used Merge statement and TOP clause at once. Let me create required objects for this demo or we can pick from earlier post,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;-- Creating tables used for merge operation 
IF ( Object_id('UsingTable') &amp;gt; 0 ) 
  DROP TABLE usingtable 

CREATE TABLE usingtable 
  ( 
     refid INT IDENTITY(1, 1), 
     name  VARCHAR(100) 
  ) 
GO

IF ( Object_id('TargetTable') &amp;gt; 0 ) 
  DROP TABLE targettable 

CREATE TABLE targettable 
  ( 
     childid INT, 
     val     INT 
  ) 
GO

-- Inserting records in both tables 
INSERT INTO usingtable 
            (name) 
VALUES      ('Target-1'), 
            ('Target-2'), 
            ('Target-3'), 
            ('Target-4'), 
            ('Target-5') 

GO 

INSERT INTO targettable 
            (childid, 
             val) 
VALUES      (1, 
             1), 
            (2, 
             2), 
            (3, 
             3), 
            (6, 
             6) 
GO &lt;/pre&gt;

&lt;p&gt;Now we will run merge statement with TOP clause and also view Target table’s data before and after script run,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SELECT * 
FROM   targettable 

MERGE TOP (2) targettable 
using usingtable 
ON ( refid = childid ) 
WHEN matched AND childid = 3 THEN 
  DELETE 
WHEN matched THEN 
  UPDATE SET val = val + 5 
WHEN NOT matched BY target THEN 
  INSERT(childid, 
         val) 
  VALUES(4, 
         4) 
WHEN NOT matched BY source THEN 
  DELETE; 

SELECT * 
FROM   targettable 

GO&lt;/pre&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;&lt;strong&gt;Merge with TOP clause&lt;/strong&gt;&lt;/em&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=47e9b9fac18c4ceb8f0cad6b539149e8&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MergeWothTop_1" border="0" alt="MergeWothTop_1" src="http://media.beyondrelational.com/images.ashx?id=e2686430e4844805913db022fd5f5ef7&amp;amp;w=-1&amp;amp;h=-1" width="430" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Merge without TOP clause&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=5cb0f07e59bb4bdd8e62ab9eed582af0&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MergeAithTop_2" border="0" alt="MergeAithTop_2" src="http://media.beyondrelational.com/images.ashx?id=951a9c0b466845029b1e9157aeba210d&amp;amp;w=-1&amp;amp;h=-1" width="432" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see from both images, with Merge statement with TOP clause updated only 2 rows and remaining insert and delete operation not happened which happened with Merge statement without TOP clause. Did you used both at once?&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=9XeHs4N_OFY:DoqpAQGeuTY:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=9XeHs4N_OFY:DoqpAQGeuTY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=9XeHs4N_OFY:DoqpAQGeuTY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=9XeHs4N_OFY:DoqpAQGeuTY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=9XeHs4N_OFY:DoqpAQGeuTY:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/9XeHs4N_OFY" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/18979/merge-statement-with-top-clause-sql-server.aspx</guid><pubDate>Sun, 17 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/18979/merge-statement-with-top-clause-sql-server.aspx</feedburner:origLink></item><item><title>Question of the month February 2013 - How does HAVING clause work without GROUP BY Clause?</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/f5RZvRrKZxQ/question-of-the-month-february-2013-how-does-having-clause-work-without-group-by-clause.aspx</link><description>&lt;P&gt;When you run the following code&lt;/P&gt;&lt;PRE class=brush:sql&gt;select name from sys.objects
having 1=1
&lt;/PRE&gt;&lt;BR&gt;you get the following error &lt;PRE class=brush:sql&gt;Msg 8120, Level 16, State 1, Line 2
Column 'sys.objects.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
&lt;/PRE&gt;&lt;BR&gt;But the follwing query runs fine without any problem &lt;PRE class=brush:sql&gt;
select 1
having 1=1

&lt;/PRE&gt;How does the second query work without any GROUP BY clause?&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=f5RZvRrKZxQ:X2mFwcUwyBc:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=f5RZvRrKZxQ:X2mFwcUwyBc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=f5RZvRrKZxQ:X2mFwcUwyBc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=f5RZvRrKZxQ:X2mFwcUwyBc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=f5RZvRrKZxQ:X2mFwcUwyBc:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/f5RZvRrKZxQ" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/70/posts/18881/question-of-the-month-february-2013-how-does-having-clause-work-without-group-by-clause.aspx</guid><pubDate>Wed, 13 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/70/posts/18881/question-of-the-month-february-2013-how-does-having-clause-work-without-group-by-clause.aspx</feedburner:origLink></item><item><title>Could not find the Distributor or the distribution database for the local server-Error while posts a tracer token in Replication</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/B4b2ZwzeJoc/could-not-find-the-distributor-or-the-distribution-database-for-the-local-server-error-while-posts-a-tracer-token-in-replication.aspx</link><description>&lt;p&gt;A few days back, I spoke about the &lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18732/how-to-manual-failover-mirroring-without-affecting-replication-sql-server.aspx" target="_blank"&gt;&lt;font size="4"&gt;&lt;strong&gt;manual failover of mirroring&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt; and also explained one issue and workaround too. Continuing with the same failover, I want to express one more issue here. This issue is not very critical but it somehow to create an issue while collecting some information for report or any other purpose. Let me elaborate everything here, why and how this error raised.&lt;/p&gt;  &lt;p&gt;You all know about system stored procedure &lt;a href="http://msdn.microsoft.com/en-us/library/ms176091(v=sql.90).aspx" target="_blank"&gt;&lt;em&gt;&lt;font size="4"&gt;sys.sp_posttracertoken&lt;/font&gt;&lt;/em&gt;&lt;/a&gt; which posts a tracer token into the transaction log at the Publisher and begins the process of tracking latency statistics. which we can schedule on some frequency to post tracer tokens. Tracer tokens can be inserted with Replication monitor also,&lt;/p&gt;  &lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=364e49e58fe64ba4b2461d63019f24f4&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="tracetoken_1" border="0" alt="tracetoken_1" src="http://media.beyondrelational.com/images.ashx?id=93b3d29bc6c247779f639517164256ab&amp;amp;w=-1&amp;amp;h=-1" width="635" height="141"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can find tsql code for same below which must be run against publisher database,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;USE publisherdb 
GO

DECLARE @out_tracer_token_id INT 

EXEC sys.Sp_posttracertoken 
  @publication = N'&amp;lt;Publication Name&amp;gt;',  -- Put Publication name here
  @tracer_token_id=@out_tracer_token_id out 

SELECT @out_tracer_token_id &lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;Error&lt;/font&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;But after failover when I tried same tsql code in switched publisher database I received an error,&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font color="#ff0000"&gt;"Could not find the Distributor or the distribution database for the local server.&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font color="#ff0000"&gt;The Distributor may not be installed, or the local server may not be configured as a Publisher at the Distributor." 
      &lt;br&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;Solution&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This script was running fine in original publisher database before failover. During investigation as per error message I found &lt;a href="http://msdn.microsoft.com/en-us/library/ms177504.aspx" target="_blank"&gt;&lt;em&gt;sp_helpdistributor&lt;/em&gt;&lt;/a&gt; was returning NULL values in publisher database. &lt;a href="http://msdn.microsoft.com/en-us/library/ms190323.aspx" target="_blank"&gt;sp_helpdistpublisher&lt;/a&gt;&lt;em&gt;&lt;/em&gt; also not showing publisher in Distributor server or server where distribution database belongs to. That means we have to do two things,&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Configure distributor at publisher. &lt;/li&gt;

  &lt;li&gt;Configure publisher at distributor. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So moving ahead towards the solution and apply below solution,&lt;/p&gt;

&lt;p&gt;1.&amp;nbsp; sp_adddistributor which creates an entry in linked server and executed at publisher in master database to configure remote distributor,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;Use master
GO

EXEC sp_adddistributor  
           @distributor=  '&amp;lt;Distributor&amp;gt;' , -- Put your distributor server name here
           @password= 'testpwd' -- password of distributor_admin &lt;/pre&gt;

&lt;p&gt;2. sp_adddistpublisher configures a publisher in distributor server which executed at distributor side in master database,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE master
GO

EXEC sp_adddistpublisher 
	 @publisher= '&amp;lt;Publisher&amp;gt;'  -- Put publisher servername here
	,@distribution_db= 'distribution'  -- Distribution database name
	,@security_mode= 1 
	,@login= 'sa' 
	,@password= 'testpwd' &lt;/pre&gt;

&lt;p&gt;After this workaround I was able to ran this script successfully at publisher and scheduled to every 5 minutes, so I can used it for &lt;em&gt;&lt;u&gt;replication latency alert and reports&lt;/u&gt;&lt;/em&gt; too.&amp;nbsp; Are you using sys.Sp_posttracertoken system stored procedure? Share your feedback here.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=B4b2ZwzeJoc:enfFhhUIZ9o:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=B4b2ZwzeJoc:enfFhhUIZ9o:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=B4b2ZwzeJoc:enfFhhUIZ9o:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=B4b2ZwzeJoc:enfFhhUIZ9o:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=B4b2ZwzeJoc:enfFhhUIZ9o:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/B4b2ZwzeJoc" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/18945/could-not-find-the-distributor-or-the-distribution-database-for-the-local-server-error-while-posts-a-tracer-token-in-replication.aspx</guid><pubDate>Tue, 12 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/18945/could-not-find-the-distributor-or-the-distribution-database-for-the-local-server-error-while-posts-a-tracer-token-in-replication.aspx</feedburner:origLink></item><item><title>#0239 - SQL Server 2012 - Msg 402 - The data types datetime and time are incompatible in the add/subtract operator</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/EPt_Y4naMV8/0239-sql-server-2012-msg-402-the-data-types-datetime-and-time-are-incompatible-in-the-addsubtract-operator.aspx</link><description>&lt;p&gt;Microsoft SQL Server 2008 came with a wide array of T-SQL enhancements. One of them was the ability to split a &lt;a href="http://msdn.microsoft.com/en-us/library/ms187819.aspx"&gt;DATETIME&lt;/a&gt; value into &lt;a href="http://msdn.microsoft.com/en-us/library/bb630352.aspx"&gt;DATE&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/bb677243.aspx"&gt;TIME&lt;/a&gt; values. From a storage standpoint this allowed us to store and bind (on the UI) date and time values separately, while appending the values when displaying on a report or exporting to a 3rd party system. They are also useful to store time revisions with respect to a DATETIME value. &lt;/p&gt;  &lt;p&gt;Here’s a quick example:&lt;/p&gt;  &lt;h2&gt;SQL Server 2008/2008 R2&lt;/h2&gt;  &lt;p&gt;In the query below, I will be taking two variables - a DATETIME and a TIME value and then add and subtract the TIME value from the DATETIME value to get the final result.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;--Please execute on a SQL 2008/2008 R2 instance
USE tempdb;
GO
DECLARE @tDate DATETIME = '2013-02-11 00:00:00.000';
DECLARE @tTime TIME = '08:00:00.000';

SELECT @tDate AS DateTimeSource, 
       @tTime AS TimeSource,
       (@tDate + @tTime) AS DateTimeAddResult,
       (@tDate - @tTime) AS DateTimeSubtractResult;
GO&lt;/pre&gt;

&lt;p&gt;The output of the above query is shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=a6c447ea9d514ad0b39ef934e90f7e75&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://media.beyondrelational.com/images.ashx?id=315f0a3c2cbf4fd7985b69e61123bacc&amp;amp;w=-1&amp;amp;h=-1" width="644" height="97" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As you can see, we were able to successfully add and subtract the DATE and the TIME values to create corresponding DATETIME values.&lt;/p&gt;

&lt;h2&gt;Changes in SQL Server 2012&lt;/h2&gt;

&lt;p&gt;If your application uses code similar to the one shown above, it will not work as expected in SQL Server 2012 (SQL 11/”Denali”):&lt;/p&gt;

&lt;pre class="brush: sql"&gt;--Please execute on a SQL 2012 instance
USE tempdb;
GO
DECLARE @tDate DATETIME = '2013-02-11 00:00:00.000';
DECLARE @tTime TIME = '08:00:00.000';

SELECT @tDate AS DateTimeSource, 
       @tTime AS TimeSource,
       (@tDate + @tTime) AS DateTimeAddResult;

SELECT @tDate AS DateTimeSource, 
       @tTime AS TimeSource,
       (@tDate - @tTime) AS DateTimeSubtractResult;
GO&lt;/pre&gt;

&lt;p&gt;The following error message is encountered:&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;Msg 402, Level 16, State 1, Line 6 
    &lt;br /&gt;The data types datetime and time are incompatible in the add operator. 

    &lt;br /&gt;Msg 402, Level 16, State 1, Line 10 

    &lt;br /&gt;The data types datetime and time are incompatible in the subtract operator.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;As you can see, SQL Server 2012 no longer allows us to add/subtract a TIME value from a DATETIME value using the conventional Add (+) and Subtract (-) operators.&lt;/p&gt;

&lt;h3&gt;Workaround&lt;/h3&gt;

&lt;p&gt;A workaround to this issue is to modify the code such that the TIME value is converted to a DATETIME value before the&amp;#160; Add (+) or Subtract (-) operation takes place.&lt;/p&gt;

&lt;pre class="brush: sql"&gt;--Please execute on a SQL 2012 instance
USE tempdb;
GO
DECLARE @tDate DATETIME = '2013-02-11 00:00:00.000';
DECLARE @tTime TIME = '08:00:00.000';

SELECT @tDate AS DateTimeSource, 
       @tTime AS TimeSource,
       (@tDate + CAST(@tTime AS DATETIME)) AS DateTimeAddResult,
       (@tDate - CAST(@tTime AS DATETIME)) AS DateTimeSubtractResult;
GO&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=fcfe58febb494be1b991af80841eb551&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://media.beyondrelational.com/images.ashx?id=55fa4e6b76bb4ea1b98e98399c15419b&amp;amp;w=-1&amp;amp;h=-1" width="644" height="97" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Between just two releases, this is a considerably major change because one may have a considerable number of objects written using this ability of DATETIME and DATE/TIME data-types to add/subtract. With an upgrade of the database to SQL Server 2012, these objects will need to be modified. I would therefore present the following questions before you:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Have you faced this issue in your migration from SQL Server 2008 to SQL Server 2012?&lt;/li&gt;

  &lt;li&gt;What solution/workaround did you apply?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Reference:&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DATETIME datatype: &lt;a title="http://msdn.microsoft.com/en-us/library/ms187819.aspx" href="http://msdn.microsoft.com/en-us/library/ms187819.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms187819.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;DATE datatype: &lt;a title="http://msdn.microsoft.com/en-us/library/bb630352.aspx" href="http://msdn.microsoft.com/en-us/library/bb630352.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb630352.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;TIME datatype: &lt;a title="http://msdn.microsoft.com/en-us/library/bb677243.aspx" href="http://msdn.microsoft.com/en-us/library/bb677243.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb677243.aspx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Until we meet next time, &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="http://www.cars.com/go/advice/Story.jsp?section=top&amp;amp;subject=more&amp;amp;story=top10annoying&amp;amp;referer&amp;amp;year&amp;amp;aff=national"&gt;&lt;strong&gt;Be courteous. Drive responsibly.&lt;/strong&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=EPt_Y4naMV8:APNHUAnLfcE:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=EPt_Y4naMV8:APNHUAnLfcE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=EPt_Y4naMV8:APNHUAnLfcE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=EPt_Y4naMV8:APNHUAnLfcE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=EPt_Y4naMV8:APNHUAnLfcE:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/EPt_Y4naMV8" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/77/Posts/18855/0239-sql-server-2012-msg-402-the-data-types-datetime-and-time-are-incompatible-in-the-addsubtract-operator.aspx</guid><pubDate>Mon, 11 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/77/Posts/18855/0239-sql-server-2012-msg-402-the-data-types-datetime-and-time-are-incompatible-in-the-addsubtract-operator.aspx</feedburner:origLink></item><item><title>SSIS - Split single row to Multiple rows</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/MWzMRLTj0SI/ssis-split-single-row-to-multiple-rows.aspx</link><description>&lt;p&gt;&lt;font face="Tahoma"&gt;Its been a long long time since I have blogged. So have I been away from forums hence no ideas to blog. I was back at forum today and got a nice scenario. How do you split a single row to multiple rows? The input file has only one row.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;There can be 2 scenarios which arise:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;&lt;font color="#ff8040"&gt;Scenario 1&lt;/font&gt;. the number of columns expected for each output row are the same.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;&lt;font color="#0080ff"&gt;Input&lt;/font&gt;: 1*1*1~2*2*2~3*3*3~4*4*4&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;Treat “~” as the row delimiter and * as the pipe delimiter&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0080ff" face="Tahoma"&gt;Expected Output:&lt;/font&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="200" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;1&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;1&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;1&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;2&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;2&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;2&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;3&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;4&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="75"&gt;&lt;font face="Tahoma"&gt;4&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="82"&gt;&lt;font face="Tahoma"&gt;4&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;&lt;font color="#ff8040"&gt;Scenario 2&lt;/font&gt;. The number of rows for each output row are different. We need to default values if we have less than expected columns and ignore the extra columns.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0080ff" face="Tahoma"&gt;Input:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;1*1*1*1~2*2~3*3*3*3*3*3*3~4*4&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;Treat “~” as the row delimiter and * as the pipe delimiter&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0080ff" face="Tahoma"&gt;Expected Output:&lt;/font&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="200" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;1&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;1&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;1&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;2&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;2&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="67"&gt;&lt;font face="Tahoma"&gt;3&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="64"&gt;&lt;font face="Tahoma"&gt;4&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="75"&gt;&lt;font face="Tahoma"&gt;4&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="82"&gt;&lt;font face="Tahoma"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;Notice the blanks in the 3rd column for 2nd and 4th row. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8040" face="Tahoma"&gt;SOLUTION:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0080ff" face="Tahoma"&gt;Case 1:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;This is simple you just need to setup the Flat File connection manager with a row delimiter as “~” and Column Delimiter as “*”&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=9ea09981e86444398f0ad13187d61ecc&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img title="images[1]" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="images[1]" src="http://media.beyondrelational.com/images.ashx?id=d627dfc667c743269d1c24086707f44e&amp;amp;w=-1&amp;amp;h=-1" width="537" height="484"&gt;&lt;/a&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;This will give us the expected results.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;Now Let us see at the &lt;font color="#0080ff"&gt;2nd Case&lt;/font&gt;.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;What will happen if we take the second file as the source and set it up similarly? Have a look at the image below:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=c3576ba4d73a4f388ec0211e9109e32e&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img title="images[1]" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="images[1]" src="http://media.beyondrelational.com/images.ashx?id=22e5e3bc3eda410d95b9962da896d992&amp;amp;w=-1&amp;amp;h=-1" width="537" height="484"&gt;&lt;/a&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;This image above shows the output data as correctly formed however we have one extra column as per out requirement. We can remove this extra column while mapping to the destination.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;When you run the package and view the same data in the Data Viewer you will see the output as below which is again not what we expect but if we do not map the last columns to the destination our job is done.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=421afe5a494d447e8012220d49fb59fb&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img title="images[1]" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="images[1]" src="http://media.beyondrelational.com/images.ashx?id=15b95714e3ef4cf98d9e0ef0f624458a&amp;amp;w=-1&amp;amp;h=-1" width="644" height="184"&gt;&lt;/a&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8040" face="Tahoma"&gt;CONCLUSION:&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font face="Tahoma"&gt;SSIS In this case first splits the row based on row delimiter and then based on Column Delimiter &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Tahoma"&gt;SSIS decides the number of columns in output based on the number of columns available in the 1st row (in case above the number of “*” before we get a “~”) &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Tahoma"&gt;If there are more number of column delimiters than in the first row the extra data goes to the last column, before the next row delimiter is received(see row 3 above) &lt;/font&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;Approach to be taken for case 2:&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font face="Tahoma"&gt;At package design time, set up a file with 1st row having one more column than expected in the final output. &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Tahoma"&gt;Map all columns to the destination except the last one. &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Tahoma"&gt;Once designed, remove the extra column set up in Step one. &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Tahoma"&gt;Job achieved very easily. &lt;/font&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;I was earlier thinking of writing a code in Script Component to achieve this, but while preparing this blog I got this method. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;Let me know what you think of this method.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;I will also post code that is required to achieve this. Decision is yours which method you choose.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Tahoma"&gt;C#&lt;/font&gt;&lt;/p&gt;  &lt;pre class="brush: csharp"&gt;&lt;font face="Tahoma"&gt;#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.IO;
#endregion

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{

    //StramReader to read the input file stream
    private StreamReader textReader;
    //String to save the source file path
    private string SrcFilePath;

    //Int to count the number of records read.
    private int i = 0;


    //Override the AcquireConnections Method to set up the connection once for the file.
    public override void AcquireConnections(object Transaction)
    {
        SrcFilePath = @"H:\MSBI\SSIS\2012\Input\SingleRowToMultiple.txt";
    }

    public override void PreExecute()
    {
        base.PreExecute();
        //Set the textReader at the PreExecute Phase so that we donot initialize it for each record.
        textReader = new StreamReader(SrcFilePath);
    }

    public override void PostExecute()
  {
        base.PostExecute();

        //Close the Text reader once the file has been read in the PostExecute Phase.
        textReader.Close();
    }


    public override void CreateNewOutputRows()
    {
        string nextLine;
        string[] rows;
        string[] columns;
        char[] rowDelimiters;
        char[] colDelimiters;
        rowDelimiters = "~".ToCharArray();
        colDelimiters = "*".ToCharArray();

        //Read next line from the file to the string variable
        nextLine = textReader.ReadLine();

        //Read the file till nextLine variable is not NULL ie. EOF
        while (nextLine != null)
        {
            if (i &amp;gt;= 0 &amp;amp;&amp;amp; nextLine.Length &amp;gt; 0)
            {
                
                //Split the records by ~ to later extract the data and in each record.
                rows = nextLine.Split(rowDelimiters);
                {
                    foreach (string row in rows)
                    {
                        // Add new row to Script Component Output
                        this.Output0Buffer.AddRow();

                            // Split the row to columns based on *
                            columns = row.Split(colDelimiters);

                            this.Output0Buffer.Column0 = columns.Length &amp;gt; 0 ? columns[0] : string.Empty;
                            this.Output0Buffer.Column1 = columns.Length &amp;gt; 1 ? columns[1] : string.Empty;
                            this.Output0Buffer.Column2 = columns.Length &amp;gt; 2 ? columns[2] : string.Empty;
                            this.Output0Buffer.Column3 = columns.Length &amp;gt; 3 ? columns[3] : string.Empty;
                    }
                }
            }
            i++;
            //Read the next line
            nextLine = textReader.ReadLine();
        }
    }

}&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;&lt;font face="treb"&gt;&lt;/font&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWzMRLTj0SI:lBRQBpNIViw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWzMRLTj0SI:lBRQBpNIViw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWzMRLTj0SI:lBRQBpNIViw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=MWzMRLTj0SI:lBRQBpNIViw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=MWzMRLTj0SI:lBRQBpNIViw:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/MWzMRLTj0SI" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/106/Posts/18919/ssis-split-single-row-to-multiple-rows.aspx</guid><pubDate>Wed, 06 Feb 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/106/Posts/18919/ssis-split-single-row-to-multiple-rows.aspx</feedburner:origLink></item><item><title>#0235 - SQL Server - T-SQL Deprecated feature - Start using semi-colons as statement-terminators</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/umelaVIc9Zg/0235-sql-server-t-sql-deprecated-feature-start-using-semi-colons-as-statement-terminators.aspx</link><description>&lt;p&gt;A while ago, I read a &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2012/12/21/16567.aspx"&gt;post&lt;/a&gt; from Aaron Bertrand (&lt;a href="http://sqlblog.com/blogs/aaron_bertrand"&gt;B&lt;/a&gt;|&lt;a href="http://twitter.com/AaronBertrand"&gt;T&lt;/a&gt;) regarding an appeal to start using semi-colons actively as statement terminators. Semi-colons as statement-terminators has been around for as long as I can remember, however, they have only been made mandatory in the newer statements:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A semi-colon is required before the WITH clause (as in Common Table Expressions, CTE) &lt;/li&gt;    &lt;li&gt;The MERGE statement must end with a semi-colon &lt;/li&gt;    &lt;li&gt;In SQL 2012, the THROW statement also requires that the preceding statement ends with a semi-colon &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Because the semi-colon is not mandatory, most developers do not use semi-colons in the T-SQL queries that they write. However as Aaron points out, it is already documented in &lt;a href="http://msdn.microsoft.com/en-us/library/ms177563.aspx"&gt;Books On Line&lt;/a&gt; that the semi-colon will be a required feature:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Although the semicolon is not required for most statements in this version of SQL Server, it will be required in a future version.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;For most teams, this would mean to modify almost every line of code and a huge testing &amp;amp; development effort. To mitigate the high development effort and bring reliability in the process, teams may decide to write a small program that would add semi-colons after each statement. But there’s a small catch.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;Exception to the rule:&lt;/strong&gt; The batch separator cannot be suffixed by a semi-colon.&lt;/p&gt; &lt;/blockquote&gt;  &lt;pre class="brush: sql"&gt;USE AdventureWorks2012;
GO;&lt;/pre&gt;

&lt;p&gt;The code above would simply fail to compile with the following error.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000" size="2" face="Consolas"&gt;Msg 102, Level 15, State 1, Line 2 
    &lt;br /&gt;Incorrect syntax near 'GO'.&lt;/font&gt; 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The reason is quite simple – a T-SQL statement is a sub-set of a batch. Because “GO” is a batch separator, it cannot be suffixed by a statement terminator because an active T-SQL batch would not exist at that time.&lt;/p&gt;

&lt;h3&gt;Reference:&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2012/12/21/16567.aspx"&gt;Ladies and Gentlemen, start your semi-colons!&lt;/a&gt; by Aaron Bertrand (&lt;a href="http://sqlblog.com/blogs/aaron_bertrand"&gt;B&lt;/a&gt;|&lt;a href="http://twitter.com/AaronBertrand"&gt;T&lt;/a&gt;) &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms177563.aspx"&gt;T-SQL Syntax Conventions&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://bit.ly/Y3GDrp"&gt;“GO” as Batch Separator – Customize batch separator in SSMS &amp;amp; SQLCMD&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Until we meet next time, &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="http://www.cars.com/go/advice/Story.jsp?section=top&amp;amp;subject=more&amp;amp;story=top10annoying&amp;amp;referer&amp;amp;year&amp;amp;aff=national"&gt;&lt;strong&gt;Be courteous. Drive responsibly.&lt;/strong&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=umelaVIc9Zg:uQiFEcJWDhY:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=umelaVIc9Zg:uQiFEcJWDhY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=umelaVIc9Zg:uQiFEcJWDhY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=umelaVIc9Zg:uQiFEcJWDhY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=umelaVIc9Zg:uQiFEcJWDhY:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/umelaVIc9Zg" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/77/Posts/18704/0235-sql-server-t-sql-deprecated-feature-start-using-semi-colons-as-statement-terminators.aspx</guid><pubDate>Mon, 28 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/77/Posts/18704/0235-sql-server-t-sql-deprecated-feature-start-using-semi-colons-as-statement-terminators.aspx</feedburner:origLink></item><item><title>Merge statement and identity insert - SQL Server</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/hFwwEw7QjuE/merge-statement-and-identity-insert-sql-server.aspx</link><description>&lt;p&gt;Today I asked by my friend for merge statement and identity insert, how to insert identity column data using merge statement? I posted for the &lt;strong&gt;&lt;font size="4"&gt;&lt;a href="http://beyondrelational.com/modules/2/blogs/88/posts/10120/merge-statement-a-new-tsql-feature-of-sql-server-2008.aspx" target="_blank"&gt;merge statement without identity insert&lt;/a&gt;. &lt;/font&gt;&lt;/strong&gt;Please read that post first before move ahead. so I would like to publish my friend’s question and answer too. It’s nothing but simple as identity insert for single table without merge.&lt;/p&gt;  &lt;p&gt;Let me generate objects required for demo,&lt;/p&gt;  &lt;pre class="brush: sql"&gt;IF ( Object_id('EmpList1', 'U') &amp;gt; 0 ) 
  DROP TABLE emplist1 

IF ( Object_id('EmpList2', 'U') &amp;gt; 0 ) 
  DROP TABLE emplist2 

CREATE TABLE emplist1 
  ( 
     seq1     INT NOT NULL IDENTITY(1, 1), 
     empid1   INT NOT NULL PRIMARY KEY, 
     empname1 VARCHAR(50) 
  ) 

CREATE TABLE emplist2 
  ( 
     seq2     INT NOT NULL IDENTITY(1, 1), 
     empid2   INT NOT NULL PRIMARY KEY, 
     empname2 VARCHAR(50) 
  ) 

INSERT INTO emplist1 
VALUES      (1001, 
             'Emp1001') 

INSERT INTO emplist2 
VALUES      (1001, 
             'Emp2001') 

INSERT INTO emplist2 
VALUES      (1002, 
             'Emp2002') 

DELETE FROM emplist2 
WHERE  seq2 = 2 

INSERT INTO emplist2 
VALUES      (1002, 
             'Emp2002') 

SELECT * 
FROM   emplist1 

SELECT * 
FROM   emplist2 &lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;a href="http://media.beyondrelational.com/images.ashx?id=c6345cf5f9c04d5db232a3852383a02c&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="merge_identity_1" border="0" alt="merge_identity_1" src="http://media.beyondrelational.com/images.ashx?id=3aec89bb19054dd982c66b5913e4804d&amp;amp;w=-1&amp;amp;h=-1" width="385" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see in the script and image where we have to update and insert record in table &lt;em&gt;emplist1&lt;/em&gt; from &lt;em&gt;emplist2&lt;/em&gt;. where record with &lt;em&gt;seq1 will be updated&lt;/em&gt; and record with &lt;em&gt;seq3 will be inserted with an identity. &lt;/em&gt;&lt;strong&gt;So emplist1 will become a target and emplist2 will become a source for this operation&lt;/strong&gt;. Let me put a script here for same,&lt;/p&gt;

&lt;pre class="brush: sql"&gt;SET IDENTITY_INSERT emplist1 ON 

MERGE emplist1 
USING emplist2 
ON ( empid1 = empid2 ) 
WHEN matched THEN 
  UPDATE SET empname1 = empname2 
WHEN NOT matched BY target THEN 
  INSERT(seq1, 
         empid1, 
         empname1) 
  VALUES(seq2, 
         empid2, 
         empname2) 
WHEN NOT matched BY source THEN 
  DELETE; 

SET IDENTITY_INSERT emplist1 OFF &lt;/pre&gt;

&lt;p&gt;You can see I used IDENTITY_INSERT at top and identity column on code while inserting records. Now checking records after end,&lt;/p&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=e10e91d607df493f8536c0544feedf2a&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="merge_identity_2" border="0" alt="merge_identity_2" src="http://media.beyondrelational.com/images.ashx?id=a323825656014bfd9719da76ec71fe64&amp;amp;w=-1&amp;amp;h=-1" width="380" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; I know you know about this, but I shared this post because I never used merge statement and identity insert at once. Did you ever used?&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hFwwEw7QjuE:jecy9R6tvIQ:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hFwwEw7QjuE:jecy9R6tvIQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hFwwEw7QjuE:jecy9R6tvIQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=hFwwEw7QjuE:jecy9R6tvIQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=hFwwEw7QjuE:jecy9R6tvIQ:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/hFwwEw7QjuE" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/18850/merge-statement-and-identity-insert-sql-server.aspx</guid><pubDate>Fri, 25 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/18850/merge-statement-and-identity-insert-sql-server.aspx</feedburner:origLink></item><item><title>Different ways to find End of the month</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/pXR7XL605Us/different-ways-to-find-end-of-the-month.aspx</link><description>&lt;P&gt;You may need to often find the end of the month for various monthly analysis. In this case you need to take all data from 1st of month to end of month.&lt;/P&gt;
&lt;P&gt;Consider the following set of data&amp;nbsp;&lt;/P&gt;&lt;PRE class=brush:sql&gt;Create table #test(date_col datetime)

insert into #test(date_col)
select '20120104' union all
select '19990605' union all
select '19960221' union all
select '19981212' union all
select '20000228' 


&lt;/PRE&gt;
&lt;P&gt;There are many ways to find out the end of the month. Here are some I knew&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Method 1 : Use DATEADD and DATEDIFF combination&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;select 
	date_col,dateadd(month,datediff(month,0,date_col)+1,-1) as end_of_month 
from 
	#test
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Method&amp;nbsp;2 : Subtract day value from date&lt;/STRONG&gt; &lt;/P&gt;&lt;PRE class=brush:sql&gt;select 
	date_col,dateadd(month,1,date_col -day(date_col)+1)-1 as end_of_month 
from 
	#test
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#ff0000&gt;Method 3 : Find first day of next month and sbtract 2 milliseconds&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;select 
	date_col,
	dateadd(millisecond ,-2,dateadd(month, datediff(month,0,date_col)+1,0)) as end_of_month 
from 
	#test
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Method 4 : Find Jan 1 of that year and add month value&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;select 
	date_col,
	dateadd(month,month(date_col),dateadd(year,datediff(year,0,date_col),0))-1 as end_of_month 
from 
	#test
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Method 5 : Use EOMONTH function (Version 2012 onwards)&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;select 
	date_col,
	eomonth(date_col ) as end_of_month 
from 
	#test&lt;/PRE&gt;In all cases, the results are as follows (except that method 3 will have time part too) &lt;PRE class=brush:sql&gt;date_col                  end_of_month
-----------------------   -----------------------
2012-01-04 00:00:00.000   2012-01-31 00:00:00.000
1999-06-05 00:00:00.000   1999-06-30 00:00:00.000
1996-02-21 00:00:00.000   1996-02-29 00:00:00.000
1998-12-12 00:00:00.000   1998-12-31 00:00:00.000
2000-02-28 00:00:00.000   2000-02-29 00:00:00.000
&lt;/PRE&gt;&lt;BR&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt; : &lt;STRONG&gt;&lt;FONT color=#ff0000&gt;Method 3&lt;/FONT&gt;&lt;/STRONG&gt; that depends on millisecond value may not be reliable. If the date has time value along with it, it may not work&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=pXR7XL605Us:1HAEB6uVD2o:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=pXR7XL605Us:1HAEB6uVD2o:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=pXR7XL605Us:1HAEB6uVD2o:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=pXR7XL605Us:1HAEB6uVD2o:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=pXR7XL605Us:1HAEB6uVD2o:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/pXR7XL605Us" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/70/posts/18723/different-ways-to-find-end-of-the-month.aspx</guid><pubDate>Mon, 21 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/70/posts/18723/different-ways-to-find-end-of-the-month.aspx</feedburner:origLink></item><item><title>How to manual failover mirroring without affecting replication-SQL Server</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/Te9rAS7UvHk/how-to-manual-failover-mirroring-without-affecting-replication-sql-server.aspx</link><description>&lt;p&gt;Before a couple of days we planned to manual failover of production servers and all live databases for that instance to mirror instance and did a failover too. It was a best experience for failover without fail anything like replication, scheduled jobs, linked servers, ssis packages, reports, windows tasks and whatever dependencies . Well perfect planning and team work were key for that succeed failover for us. This post is about to considering mirroring without witness server\automatic failover and transactional&amp;nbsp;replication &amp;nbsp;where&amp;nbsp;production&amp;nbsp;database act as a publisher and&amp;nbsp;principal&amp;nbsp;and the plan for same like following,&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;Planning&lt;/font&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Configured&amp;nbsp;mirror all production databases to mirror instance without witness server. &lt;/li&gt;    &lt;li&gt;Created a dns alias for production server. &lt;/li&gt;    &lt;li&gt;Used that alias as a data source to connect production sql server instance in linked servers, reports, ssis packages in all servers which pointing production instance and in application too . &lt;/li&gt;    &lt;li&gt;Created all scheduled jobs with disable status in mirror instance. &lt;/li&gt;    &lt;li&gt;Created all linked servers of production instance in mirror instance. &lt;/li&gt;    &lt;li&gt;Created all logins of production instance in mirror instance. &lt;/li&gt;&lt;li&gt;Created all database mail profiles of production instance in mirror instance.&lt;/li&gt;    &lt;li&gt;Created sql server agent operators of production instance in mirror instance. &lt;/li&gt;    &lt;li&gt;Created windows scheduled tasks with disable status in mirror server. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;All of above steps applied in advance with recent changes just before to start&amp;nbsp;failover&amp;nbsp;and need to change dns alias to mirror server, enable scheduled jobs and windows tasks during&amp;nbsp;failover. &amp;nbsp;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;Problem&lt;/font&gt;&amp;nbsp;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;But had a little bit confusion for&amp;nbsp;&lt;strong&gt;replication,&lt;/strong&gt;&amp;nbsp;How to manually&amp;nbsp;failover&amp;nbsp;of mirroring without affecting replication? That was an issue. I have applied solution and made it succeed.&amp;nbsp; After manual failover, transactional replication started to raise an error and working stopped. because it was trying to connect publisher database but it became mirror after failover,&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;The process could not execute 'sp_replcmds' on '&amp;lt;original Publisher Server&amp;gt;'.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;Workaround &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;There is one more step apart from above listed,&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add &lt;strong&gt;Failover Partner&lt;/strong&gt; as a parameter (–&lt;em&gt;PublisherFailoverPartner&lt;/em&gt;) in snapshot, log reader and queue reader agents. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;How to add parameter?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I am sharing some screen shots which drive us for the explanation, &lt;/p&gt;  &lt;p&gt;1. Go to &lt;em&gt;Replication monitor&lt;/em&gt; and move to &lt;em&gt;agent&lt;/em&gt; tab. Select agent from &lt;em&gt;Agent types&lt;/em&gt; drop box, you will have list of agent, select it and click &lt;em&gt;Agent Profiler&lt;/em&gt; from right click property.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=7496d3644ba04a3d82f9903b0450150f&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Faolver1" border="0" alt="Faolver1" src="http://media.beyondrelational.com/images.ashx?id=6984412a86934f6b8b98e79051c80f46&amp;amp;w=-1&amp;amp;h=-1" width="594" height="294"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;2. Under Agent property, create a new user profile which will be created same as system profile, just need to add value &amp;lt;failover partner&amp;gt; of –&lt;em&gt;PublisherFailoverPartner &lt;/em&gt;parameter.&lt;/p&gt;&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=02e22ca8670441a9acce3d06d88536cc&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="failover2" border="0" alt="failover2" src="http://media.beyondrelational.com/images.ashx?id=4c5d9d4da33e4ab8b98ee797f4c534ba&amp;amp;w=-1&amp;amp;h=-1" width="594" height="443"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. Add –&lt;em&gt;PublisherFailoverPartner&lt;/em&gt; parameter value for all agents like snapshot, log reader, queue reader agent and merge agent we have merge replication configured.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=cb287d9a3a8340a29ccf53daeb9fddd8&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="failover3" border="0" alt="failover3" src="http://media.beyondrelational.com/images.ashx?id=dadecafe3ce5408c921f38ccc32d18f2&amp;amp;w=-1&amp;amp;h=-1" width="594" height="198"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; : After creating a new user agent profile check the box “&lt;em&gt;&lt;u&gt;Use for this agent&lt;/u&gt;&lt;/em&gt;” . I created new agent profile because it is not allow to add –&lt;em&gt;PublisherFailoverPartner&lt;/em&gt; parameter for system profile from user interface. But we can add it with system procedures with tsql script.&lt;/p&gt;  &lt;pre class="brush: sql"&gt;USE distribution 
GO 

-- For Snapshot Agent 
EXEC sp_add_agent_parameter 
  @profile_id = 1, 
  @parameter_name = N'-PublisherFailoverPartner', 
  @parameter_value = N'&amp;lt;Failover Partner&amp;gt;' 

-- For Log Reader Agent 
EXEC sp_add_agent_parameter 
  @profile_id = 2, 
  @parameter_name = N'-PublisherFailoverPartner', 
  @parameter_value = N'&amp;lt;Failover Partner&amp;gt;' 

-- For Distribution Agent 
EXEC sp_add_agent_parameter 
  @profile_id = 3, 
  @parameter_name = N'-PublisherFailoverPartner', 
  @parameter_value = N'&amp;lt;Failover Partner&amp;gt;' 

-- For Merge Agent 
EXEC sp_add_agent_parameter 
  @profile_id = 4, 
  @parameter_name = N'-PublisherFailoverPartner', 
  @parameter_value = N'&amp;lt;Failover Partner&amp;gt;' 

-- Queue Reader Agent 
EXEC sp_add_agent_parameter 
  @profile_id = 9, 
  @parameter_name = N'-PublisherFailoverPartner', 
  @parameter_value = N'&amp;lt;Failover Partner&amp;gt;' &lt;/pre&gt;

&lt;p&gt;It is allow to add this parameter for system profiles but change the profile_id whatever system or user profile used for agent which you will get it from &lt;em&gt;&lt;u&gt;sp_help_agent_profile&lt;/u&gt;&lt;/em&gt; system procedure from &lt;em&gt;distribution&lt;/em&gt; database. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size="4"&gt;How to confirm?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With following script we can confirm the parameter values for such agents. Run this script in msdb database from distributor server.&lt;/p&gt;

&lt;pre class="brush: sql"&gt;USE msdb 
GO

SELECT a.profile_id, 
       a.profile_name, 
       a.description, 
       a.def_profile, 
       b.parameter_name, 
       b.value 
FROM   msagent_profiles a 
       INNER JOIN msagent_parameters b 
               ON ( a.profile_id = b.profile_id ) 
WHERE  b.parameter_name = '-PublisherFailoverPartner' &lt;/pre&gt;

&lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=b89e8e07536b49929cdbe522ca6047ba&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="failover4" border="0" alt="failover4" src="http://media.beyondrelational.com/images.ashx?id=5660c6b6bae6414eae210a657865c279&amp;amp;w=-1&amp;amp;h=-1" width="619" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Click on image to enlarge)&lt;/p&gt;

&lt;p&gt;Hope you enjoyed this case and might help you a lot. Did you faced this issue or what is your solution? Something missing in failover plan? Please share your ideas and opinion about it. Your comments&amp;nbsp; are most welcome!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Te9rAS7UvHk:PjDAx_Ey5YE:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Te9rAS7UvHk:PjDAx_Ey5YE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Te9rAS7UvHk:PjDAx_Ey5YE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Te9rAS7UvHk:PjDAx_Ey5YE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Te9rAS7UvHk:PjDAx_Ey5YE:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/Te9rAS7UvHk" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/18732/how-to-manual-failover-mirroring-without-affecting-replication-sql-server.aspx</guid><pubDate>Sat, 19 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/18732/how-to-manual-failover-mirroring-without-affecting-replication-sql-server.aspx</feedburner:origLink></item><item><title>Sorting mixed value strings numerically</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/VqT1VyqfzCo/sorting-mixed-value-strings-numerically.aspx</link><description>&lt;P&gt;There was a question in the forum on how to Sort mixed value strings “&lt;STRONG&gt;numerically&lt;/STRONG&gt;”&lt;/P&gt;
&lt;P&gt;Consider the following set of data&lt;/P&gt;&lt;PRE class=brush:sql&gt;create table #test(val varchar(10))
insert into #test
select '1002' union all
select '29C' union all
select '1' union all
select '205' union all
select '105A'
&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;The resultset should be sorted by taking only number part into consideration. There can be many methods and here are my two methods&lt;/P&gt;&lt;STRONG&gt;Method 1 : Remove non-numerics from string and sort them as numbers &lt;/STRONG&gt;&lt;PRE class=brush:sql&gt;select 
	* 
from 
	#test 
order by
	stuff(val+'a',patindex('%[^0-9]%',val+'a'),len(val),'')*1
&lt;/PRE&gt;&lt;BR&gt;&lt;STRONG&gt;Method 2 : Extract numerics from string and sort them as numbers &lt;/STRONG&gt;&lt;PRE class=brush:sql&gt;select 
	* 
from 
	#test 
order by
	substring(val+'a',1,patindex('%[a-zA-Z]%',val+'a')-1)*1
&lt;/PRE&gt;&lt;BR&gt;The results of the above two methods are &lt;PRE class=brush:sql&gt;val
----------
1
29C
105A
205
1002
&lt;/PRE&gt;&lt;BR&gt;&lt;STRONG&gt;Note &lt;/STRONG&gt;: I have appended a character 'a' so that every value will have atleast a single alphabet suffixed and we can avoid &lt;STRONG&gt;CASE WHEN&lt;/STRONG&gt; expressions. Also it is assumed that the string will start with a number and alphabets may or may not end with them. A string like &lt;STRONG&gt;12B78C&lt;/STRONG&gt; is invalid for this sorting.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=VqT1VyqfzCo:nKeBmA4Omvc:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=VqT1VyqfzCo:nKeBmA4Omvc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=VqT1VyqfzCo:nKeBmA4Omvc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=VqT1VyqfzCo:nKeBmA4Omvc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=VqT1VyqfzCo:nKeBmA4Omvc:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/VqT1VyqfzCo" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/70/posts/18694/sorting-mixed-value-strings-numerically.aspx</guid><pubDate>Wed, 16 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/70/posts/18694/sorting-mixed-value-strings-numerically.aspx</feedburner:origLink></item><item><title>Split strings in Proper format</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/KZt3EZcCzJw/split-strings-in-proper-format.aspx</link><description>This short tip is a result of my quick research in attempt to solve this MSDN thread
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/f02aefbd-09a5-4336-84d2-d67bdf238221

In order to use case sensitive search with PATINDEX we need to use case sensitive collation and we can not use ranges of letters, unfortunately, we need to list all possible letters.

So, this is my solution

    DECLARE @t TABLE (Col VARCHAR(20))
    
    INSERT INTO @t
    VALUES ('JohnDoe')
    	,('AvramLincoln')
    	,('Brad Pitt')
    
    SELECT Col
    	,COALESCE(STUFF(col, NULLIF(patindex('%[abcdefghijklmnopqrstuvwxyz][ABCDEFGHIJKLMNOPQRSTUVWXYZ]%', Col COLLATE SQL_Latin1_General_CP1_CS_AS), 0) + 1, 0, ' '), Col) AS NewCol
    FROM @t&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=KZt3EZcCzJw:0MvnSdakmZg:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=KZt3EZcCzJw:0MvnSdakmZg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=KZt3EZcCzJw:0MvnSdakmZg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=KZt3EZcCzJw:0MvnSdakmZg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=KZt3EZcCzJw:0MvnSdakmZg:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/KZt3EZcCzJw" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/1/justlearned/tips/18692/split-strings-in-proper-format.aspx</guid><pubDate>Thu, 10 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/1/justlearned/tips/18692/split-strings-in-proper-format.aspx</feedburner:origLink></item><item><title>Replicated transactions are waiting for next Log backup or for mirroring partner to catch up-Issue in SQL Server Replication</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/yi7-YxlYWdg/replicated-transactions-are-waiting-for-next-log-backup-or-for-mirroring-partner-to-catch-up-issue-in-sql-server-replication.aspx</link><description>&lt;p&gt;Hope you read my earlier post of "&lt;a href="http://beyondrelational.com/modules/2/blogs/88/Posts/18637/replication-components-are-not-installed-on-this-server-error-while-adding-subscriber-in-replication.aspx"&gt;&lt;i&gt;Replication components are not installed on this server&lt;/i&gt;&lt;/a&gt;" issue, you may liked it. One day suddenly replication went to high latency and i was clicked it during monitoring. I opened replication monitor, during analysis i found one message which was showing latency from publisher to distributor due to some issue. The message is as following,&lt;/p&gt;  &lt;p&gt;“&lt;em&gt;&lt;font color="#ff0000"&gt;Replicated transactions are waiting for next Log backup or for mirroring partner to catch up&lt;/font&gt;&lt;/em&gt;”. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://media.beyondrelational.com/images.ashx?id=80f0853fac574763afc80a3fc3dc8e9e&amp;amp;w=-1&amp;amp;h=-1"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="replError" border="0" alt="replError" src="http://media.beyondrelational.com/images.ashx?id=01fcbd39c36a4dc0a81bccefe1dfc118&amp;amp;w=-1&amp;amp;h=-1" width="573" height="329"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As per message i checked the transaction log backups were happened or not, checked it and &lt;strong&gt;log backups were happening&lt;/strong&gt; . Finally one option is pending to review and it is mirroring. I checked the status of mirroring&amp;nbsp; and seen principal database went to &lt;strong&gt;&lt;em&gt;synchronizing&lt;/em&gt;&lt;/strong&gt; mode. May be mirroring went in &lt;em&gt;synchronizing&lt;/em&gt; mode due to heavy or so many transactions in the route to apply at mirror database. So replication is waiting&amp;nbsp; to be synchronized status of principal database. I exactly do not why replication went in waiting even transaction log backups were happen. I checked online solution and received some of the solutions from here and it suggests following, &lt;/p&gt;  &lt;p&gt;1. EXEC sp_replicationdboption 'PublisherDB','sync with backup',false&lt;/p&gt;&lt;p&gt;This mean that not need to backed up of all transactions before being delivered to the distribution database.&amp;nbsp;Please visit this option &lt;a href="http://msdn.microsoft.com/en-us/library/ms188769.aspx"&gt;here&lt;/a&gt;&amp;nbsp;which sets a replication database option for the specified database. This stored procedure is executed at the Publisher or Subscriber on any database.&lt;/p&gt;  &lt;p&gt;2. Enable trace flag 1448&lt;/p&gt;  &lt;p&gt;After this setting&amp;nbsp;the Log Reader Agent can continue replicating changes regardless of the mirroring state. Please read more &lt;a href="http://support.microsoft.com/kb/937041"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;I never applied these suggestions. Replication and mirroring both are using transaction logs and this could be the reason why replication was in high delay status while mirroring was stuck or in process to synchronize mirror database. So i turned off mirroring and monitored replication status. Finally replication was succeed to remove delay and applied all pending commands. Then i configured mirroring again after done with replication&amp;nbsp;sync.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Conclusion&lt;/b&gt; : We have two options either to wait for&amp;nbsp;synchronized status of&amp;nbsp;principal database or turned of mirroring, getting replication synced properly and reconfigure mirroring again depend on priority and importance.It will be better to go for correct solution to avoid such issue.&lt;/p&gt;&lt;p&gt;But question is here why replication went in waiting for synchronized&amp;nbsp;of mirroring even transactions log backups happened while?&amp;nbsp;I would like you to share if received such issue and solution or any opinion which you applied to resolved it. This may help to me and all people facing same issue.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=yi7-YxlYWdg:KWIMsYWmIz4:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=yi7-YxlYWdg:KWIMsYWmIz4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=yi7-YxlYWdg:KWIMsYWmIz4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=yi7-YxlYWdg:KWIMsYWmIz4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=yi7-YxlYWdg:KWIMsYWmIz4:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/yi7-YxlYWdg" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/2/blogs/88/Posts/18664/replicated-transactions-are-waiting-for-next-log-backup-or-for-mirroring-partner-to-catch-up-issue-in-sql-server-replication.aspx</guid><pubDate>Sat, 05 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/2/blogs/88/Posts/18664/replicated-transactions-are-waiting-for-next-log-backup-or-for-mirroring-partner-to-catch-up-issue-in-sql-server-replication.aspx</feedburner:origLink></item><item><title>Getting Started with SSAS Multidimensional - Part 8: Aggregations, Partitions and Perspectives</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/DNAJe5526bc/getting-started-with-ssas-multidimensional-part-8-aggregations-partitions-and-perspectives.aspx</link><description>In our last post, we learned how to create measures in SSAS. This post will focus on building perspectives, partitions and aggregations for the project.

Before we start, it is important to understand what aggregations, partitions and perspectives are, and how they are useful. 

  - Aggregations are pre-calculated summaries of data from leaf level, and they help to improve performance by preparing the answers in advance before the questions are asked. For example, it might be useful to roll up the sales by year and store it as an aggregation. This way, if there is a query which asks the sales by year, the answer can be given directly from the aggregation rather than rolling up all the 365 days at runtime. But an important thing to note is that, it is practically impossible to create aggregations for all valid combinations. The SSAS engine creates the aggregations based on an internal cost-vs.-benefit algorithm and we can certainly aid the engine by setting the aggregation usage property to None if it is not a frequently used attribute.
  - Partitions are used to store data and aggregations for the measure groups. By default, every measure group has one partition and more partitions can be added manually (though we have to ensure that the data in each partition is mutually exclusive of each other and that there is no overlap). Having multiple partitions can be a great way of managing big cubes and can greatly improve query performance and load performance.
  - Perspectives are basically different views of the same cube. They are used when we want to just display the relevant measures or dimensions to the users, rather than overwhelming them with the entire set of cube measures and dimensions. An important thing to note is that perspectives are not a security mechanism and the security is just derived from the underlying cube. The main purpose of perspectives is to improve the user experience while interacting with the cube for analysis.

It is worthwhile to have a very high level overview of the way queries interact with the engine before we go further. Follow the steps below along with the picture to understand better:

![query execution][1]

 1. User sends query to the SSAS engine.
 2. Engine tries to resolve the result from the cache first. If it was executed before, the results would be available in the cache and the results (green arrow) are sent back to the engine and then to the user.
 3. If the results are not available in the cache, then the engine tries to resolve the request from the Aggregations. Now there are two steps here:-
    - Engine tries to find if there is an exact aggregation for the query. For example, if the query is to find the sales by 2007, engine tries to find an exact match or a direct hit. If found, it returns the result from the aggregation to the engine and then back to the user.
    - If the engine doesn’t find a direct hit, it tries to find an indirect hit. For example, it tries to see if there is an aggregation for any of the lower levels like Month. If yes, then the engine just needs to aggregate sales for the 12 months compared to 365 days, and then pass the result back to the user.
 4. If the results are not available in aggregations, then the engine checks the partitions now where the base data resides. Having multiple partitions which are carefully designed will help in query performance also. For example, if there are multiple partitions partitioned by year, then the queries just need to check in the 2007 partition and aggregate it. If there is just one partition for all the years, there is more number of rows to check, and this might cause additional delays. Anyways, the engine finds all the base rows of the measure group, aggregates it and then sends the results back to the user.

With this information in mind, we will start creating some partitions, then move on to creating aggregations and finally create the perspectives.

  - Let us partition the Fact Internet Sales measure group into two – all years before 2006 (included) and all years after 2006. For that, select the Partitions tab on the Sales cube, click on the ellipsis in the Source column for Fact Internet Sales and then change the Binding type to Query Binding. Now we can modify the query to male our partitions. Please note that we can use table binding if we already have the two tables with the data before 2006 and after in our database / DSV.

![create partitions][2]

  - Add the following statement to the WHERE clause of the query to restrict by all years less than or equal to 2006.
**left([dbo].[FactInternetSales].[OrderDateKey],4)&lt;=2006**
It is nice to note that since we had date keys of the format yyyymmdd, it is easy to get the year/month/day from it. Using auto-generated surrogate keys for Date would have made partitioning difficult as we would need to join it with the time dimension tables to get the key. So it is always a good idea to have the Date keys to be of the format yyyymmdd.

![Partition clause][3]

  - Click on **OK** and we have got our first partition made. Now click on **New Partition**, and then select the **Fact Internet Sales** as the source table in the Partition Wizard, as shown below. Click on **Next**.

![new partition][4]

  - Then check the **Specify a query to restrict rows** option.

![Restrict rows in new partition][5]

   Add the following statement to the where clause to get all rows where the year is greater than 2006.

   **left([dbo].[FactInternetSales].[OrderDateKey],4)&gt;2006**
  
 Click on **Next**.

  - Leave the Processing and Storage Locations as they are, and then click on **Next**.
  - Name the new partition, choose the Design Aggregations later option and click on **Finish**.

![new partition][6]

Now we have got the 2 required partitions.

  - To create aggregation for these 2 partitions, go to the **Aggregations** tab, click on the **Design Aggregation** icon on the top left and then select the two partitions as shown below. Click on **Next**.

![New aggregation][7]

  - In the **Review Aggregation Usage** screen, make sure to turn the option as **None** for those unimportant attributes in a real life project. For now, let’s leave everything as default and click on **Next**.

![Review aggregation usage][8]

  - In the **Specify Object Counts** screen, click on the **Count** button, and then click on **Next** when it is finished.
  - In the **Set Aggregation Options** screen, choose the appropriate option and then click on **Start**. 

![aggregation design][9]

Once it is completed, click on **Next**.

  - Rename the aggregation design and then choose the Save the aggregation but do not process them option for now. Click on **Finish**.

![aggregation][10]

  - Now that we have got our aggregation design done, lets create 2 perspectives. For that, go to the perspectives tab and then click on the New Perspective icon. Rename the new perspective, and then select a few dimensions and measures. Repeat the step for the next perspective also like shown below.

![perspective][11]

By the end of this post, we have made our partitions, aggregations and perspectives. This is all that will be covered in this post. In our next post, we will talk about processing the SSAS objects that we have created and on how we can see the result in the SSAS browser.


  [1]: http://media.beyondrelational.com/images.ashx?id=74819111f8f14e8ca1ebdda549bd892d&amp;w=628&amp;h=0
  [2]: http://media.beyondrelational.com/images.ashx?id=f86e819878964292bb3ced17fffcb1cb&amp;w=628&amp;h=0
  [3]: http://media.beyondrelational.com/images.ashx?id=a95f244239b047f3b612ceeb2c1fd5b1&amp;w=628&amp;h=0
  [4]: http://media.beyondrelational.com/images.ashx?id=2a7c5bdd695a4cd989c8c6e066182de3&amp;w=628&amp;h=0
  [5]: http://media.beyondrelational.com/images.ashx?id=d16aec98f48b42348716571e6710ed5c&amp;w=628&amp;h=0
  [6]: http://media.beyondrelational.com/images.ashx?id=9d03c1b9861c478eab440c9b681703ad&amp;w=628&amp;h=0
  [7]: http://media.beyondrelational.com/images.ashx?id=771ed717828a47ff862dd5f8ba1278ea&amp;w=628&amp;h=0
  [8]: http://media.beyondrelational.com/images.ashx?id=1592c6d6a34841328e5ac3dfbd29a24c&amp;w=628&amp;h=0
  [9]: http://media.beyondrelational.com/images.ashx?id=601ae8692abe41dc8ac67777e3c6d4b8&amp;w=628&amp;h=0
  [10]: http://media.beyondrelational.com/images.ashx?id=4e540d3ba95b4ab69ac8a6d6027f9681&amp;w=628&amp;h=0
  [11]: http://media.beyondrelational.com/images.ashx?id=1914353339524147873232a40a646c8f&amp;w=628&amp;h=0&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=DNAJe5526bc:rcCwwY0Az8U:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=DNAJe5526bc:rcCwwY0Az8U:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=DNAJe5526bc:rcCwwY0Az8U:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=DNAJe5526bc:rcCwwY0Az8U:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=DNAJe5526bc:rcCwwY0Az8U:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/DNAJe5526bc" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/12/tutorials/799/tutorials/18127/getting-started-with-ssas-multidimensional-part-8-aggregations-partitions-and-perspectives.aspx</guid><pubDate>Thu, 03 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/12/tutorials/799/tutorials/18127/getting-started-with-ssas-multidimensional-part-8-aggregations-partitions-and-perspectives.aspx</feedburner:origLink></item><item><title>Getting Started with Ajax - Part 8: Working with JSON</title><link>http://feedproxy.google.com/~r/beyondrelationalmain/~3/Xc1ky5VI6uw/getting-started-with-ajax-part-8-working-with-json.aspx</link><description>In the previous chapter, we showed how we can process XML data in AJAX application. This time, we will rewrite the XML example to work with JSON data. JSON data format is very popular with JavaScript, because it can be processed very easily, and is built into many JavaScript and AJAX libraries. Starting with XML data from previous chapter, this is what our JSON will look like:

    {
      "websites": {
        "website": [
          {
            "name": "Amazon",
            "url": "http://www.amazon.com"
          },
          {
            "name": "Google",
            "url": "http://www.google.com"
          },
          {
            "name": "Ebay",
            "url": "http://www.ebay.com"
          }
        ]
      }
    }

As you can see, there's pretty straightforward mapping from XML to JSON. Each XML tag is mapped into corresponding JSON string, and XML tags that contain multiple children are represented as an array in JSON. As before, we need to create the servlet, which will serve JSON data. This servlet will be mapped to `/ajaxjson` path. Servlet source code is shown below:

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/json");
            PrintWriter out = response.getWriter();
            try {
                out.println("{");
                out.println("\"websites\": {");
                out.println("\"website\": [");
                out.println("{\"name\": \"Amazon\", \"url\": \"http://www.amazon.com\"},");
                out.println("{\"name\": \"Google\", \"url\": \"http://www.google.com\"},");
                 out.println("{\"name\": \"Ebay\", \"url\": \"http://www.ebay.com\"}]");
                out.println("}");
                out.println("}");
            } finally {            
                out.close();
            }
        }

Finally, we need to create the page with script to send AJAX request and process the response. We will create page called `jsonpage.html`. This page contains single button, which will request data from server when clicked, and display results in table form. Complete source code can be found in attached archive, but we will focus only on callback method here, since that is where JSON processing is implemented.

    function xmlCallback(){
                    if(request.readyState == 4){
                        if(request.status == 200){
                            
                            var json = eval('(' + request.responseText + ')');
                            var txt = "&lt;table border='1'&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Site&lt;/th&gt;&lt;th&gt;URL&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;";
                            for(i = 0;i &lt; json.websites.website.length;i++){
                                txt += "&lt;tr&gt;";
                                name = json.websites.website[i].name;
                                txt += "&lt;td&gt;" + name + "&lt;/td&gt;";
                                url = json.websites.website[i].url;
                                txt += "&lt;td&gt;" + url + "&lt;/td&gt;";
                                txt += "&lt;/tr&gt;";
                            }
                            txt += "&lt;/tbody&gt;&lt;/table&gt;";
                           document.getElementById("webSiteList").innerHTML = txt;
                        }
                        
                    } 
                }

The key here is the line `var json = eval('(' + request.responseText + ')');`

Here, we create variable called “json”, which is obtained by evaluating the response sent back from server. This creates JavaScript object whose attributes represent members of data array, and can be accessed using dot notation. The rest of the callback is pretty much the same as for XML processing function, the only difference is the way we access data for name and URL (JSON-style vs. XML-style).

This simple example outlines basics of JSON processing in AJAX. By enabling your applications to handle more than one data format, they can be more easily publicly accessible and will be able to interoperate with a number of third party applications.

[You my find the sample application here.][1]



  [1]: http://beyondrelational.com/modules/12/tutorials/686/downloads/17837/ajax-sample-web-app-part-8.aspx&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Xc1ky5VI6uw:00ACuvVwj08:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Xc1ky5VI6uw:00ACuvVwj08:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Xc1ky5VI6uw:00ACuvVwj08:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?i=Xc1ky5VI6uw:00ACuvVwj08:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/beyondrelationalmain?a=Xc1ky5VI6uw:00ACuvVwj08:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/beyondrelationalmain?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/beyondrelationalmain/~4/Xc1ky5VI6uw" height="1" width="1"/&gt;</description><guid isPermaLink="false">http://beyondrelational.com/modules/12/tutorials/686/tutorials/17838/getting-started-with-ajax-part-8-working-with-json.aspx</guid><pubDate>Tue, 01 Jan 2013 00:00:00 GMT</pubDate><feedburner:origLink>http://beyondrelational.com/modules/12/tutorials/686/tutorials/17838/getting-started-with-ajax-part-8-working-with-json.aspx</feedburner:origLink></item></channel></rss>
