<rss version="2.0"><channel><title>Title</title><link>http://beyondrelational.com</link><description>description</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>Title</title><link>http://beyondrelational.com</link><width>50</width><height>50</height></image><copyright>Copyright © Beyondrelational.com</copyright><lastBuildDate>Wed, 23 May 2012 19:07:59 GMT</lastBuildDate><ttl>60</ttl><item><title>NULL, NULL, NULL and nothing but NULL</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14865/null-null-null-and-nothing-but-null.aspx</link><description>&lt;P&gt;&lt;STRONG&gt;NULL&lt;/STRONG&gt;. This is a magical word in Database programming. Here are&amp;nbsp;some interesting facts about NULL in SQL Server.&lt;/P&gt;
&lt;P&gt;1 NULL can be defined as absense of value, undefined, or the value which is unknown at this point of time.&lt;BR&gt;2 All datatypes can be defined with NULL constraint&lt;BR&gt;3 Direct usage of artimetic or logical operations on NULL will not work as expected&lt;BR&gt;4 The system functions ISNULL, COALESE and NULLIF are used only to deal with NULL&lt;BR&gt;5 NOT NULL constraint cannot be defined for a computed column until it is also PERSISTED&lt;BR&gt;6 The only datatypes that will interpret NULL differently are&amp;nbsp;rowversion and timestamp&lt;/P&gt;
&lt;P&gt;Run this code and see the output&lt;/P&gt;&lt;PRE class=brush:sql&gt;declare @rv rowversion , @ts timestamp 
select @rv=null, @ts=null
select @rv as rowversion,@ts as timestamp
&lt;/PRE&gt;&lt;BR&gt;Output is &lt;PRE class=brush:sql&gt;rowversion         timestamp
------------------ ------------------
0x                 0x
&lt;/PRE&gt;&lt;BR&gt;7 NULL=NULL will never be true unless SET ANSI_NULLS is OFF&lt;BR&gt;&lt;BR&gt;While the first query returns nothing, the second will return 6 &lt;PRE class=brush:sql&gt;--Query 1
set ansi_nulls on
select 6
where null=null

--Query 2
set ansi_nulls off
select 6
where null=null
&lt;/PRE&gt;&lt;BR&gt;The condition WHERE col IS NULL will not be affected by the above setting&lt;BR&gt;&lt;BR&gt;8&amp;nbsp;&amp;nbsp; The default datatype of NULL is INT. Refer &lt;A href="http://beyondrelational.com/modules/2/blogs/70/posts/10982/default-datatype-of-null.aspx"&gt;&lt;STRONG&gt;&lt;FONT color=#0000ff&gt;Default datatype of NULL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/A&gt; for more information&lt;BR&gt;9&amp;nbsp;&amp;nbsp; Column with UNIQUE constraint will allow only one NULL value in SQL Server (But not true in other RDBMSs)&lt;BR&gt;10 &amp;nbsp;NULL will make SQL Server to use short circuit logic in some cases&lt;BR&gt;&lt;BR&gt;Consider this example &lt;PRE class=brush:sql&gt;select 6/0/null

select null/6/0
&lt;/PRE&gt;
&lt;P&gt;While the first query throws an error the second query returns NULL&lt;/P&gt;
&lt;P&gt;11 The value NULL is not equal to string value 'NULL'&lt;BR&gt;12 By default NULL values come first when a column is ordered in ascending order and come last when ordered in descending order &lt;BR&gt;13 If you dont use GROUP BY clause, the aggregate functions will always return single value (NULL)&amp;nbsp;when the condition is false&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=brush:sql&gt;select sum(col) as col from
(
	select 45 as col
) as t
where 1=0
&lt;/PRE&gt;&lt;BR&gt;The above returns NULL &lt;BR&gt;&lt;BR&gt;14 NULL values are by default omitted in all aggregate functions&lt;BR&gt;&lt;BR&gt;Consider the following example&lt;BR&gt;&lt;PRE class=brush:sql&gt;select sum(col) as col_cum,count(col) as col_count,avg(col*1.0) as col_avg from
(
	select 1 as col union all
	select null as col union all
	select 2 as col union all
	select 3 as col 
) as t
&lt;/PRE&gt;The output is &lt;PRE class=brush:sql&gt;col_cum     col_count   col_avg
----------- ----------- -----------
6           3           2.000000
&lt;/PRE&gt;&lt;BR&gt;15 Agrregate functions cannot be directly applied over NULL value&lt;BR&gt;&lt;BR&gt;This code &lt;PRE class=brush:sql&gt;select sum(null) as null_sum&lt;/PRE&gt;returns the following error &lt;PRE class=brush:sql&gt;Msg 8117, Level 16, State 1, Line 1
Operand data type NULL is invalid for sum operator.
&lt;/PRE&gt;&lt;BR&gt;You can wonder whether NULL is a datatype </description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14865/null-null-null-and-nothing-but-null.aspx</guid><pubDate>Mon, 21 May 2012 00:00:00 GMT</pubDate></item><item><title>Use system functions cleverly</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14857/use-system-functions-cleverly.aspx</link><description>&lt;P&gt;My Co-worker complained me that AVG function is not properly working in SQL Server whereas it works correctly in mysql. I immediately told him that AVG does the implicit convertion by default and the result may be wrong (based on datatype). &lt;/P&gt;
&lt;P&gt;Consider the following set of data&lt;/P&gt;&lt;PRE class=brush:sql&gt;select avg(col) from
(
	select 1 as col union all
	select 2
) as t
&lt;/PRE&gt;The result is &lt;PRE class=brush:sql&gt;average
-----------
1
&lt;/PRE&gt;As you see, the result is not 1.5&amp;nbsp;but it is 1 becuase the return type of AVG function is same as that of column it is applied for. The datatype of col is INT and AVG function CASTs 1.5 into 1. To avoid this you need to CAST the datatype into DECIMAL (or multiply column by 1.0) &lt;PRE class=brush:sql&gt;select avg(col*1.0) as average,avg(cast(col as decimal(12,2))) as average from
(
	select 1 as col union all
	select 2
) as t
&lt;/PRE&gt;The result is &lt;PRE class=brush:sql&gt;average                                 average
--------------------------------------- ---------------------------------------
1.500000                                1.500000
&lt;/PRE&gt;So you need to aware of this when using system functions whose datatype depends on the datatype of the column</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14857/use-system-functions-cleverly.aspx</guid><pubDate>Thu, 17 May 2012 00:00:00 GMT</pubDate></item><item><title>Compare numbers stored as characters seperated by space</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14825/compare-numbers-stored-as-characters-seperated-by-space.aspx</link><description>&lt;P&gt;In SQL forums, one of the memebers asked this question. &lt;BR&gt;&lt;BR&gt;&lt;EM&gt;&lt;FONT color=#800080&gt;&lt;STRONG&gt;"In the table a varchar column has values like '2.2020 30 4.0000', '2.20200 30 4.00', etc. When I pass a parameter with the value '2.202 30 4.0' , the above value should be returned as output. How do I do it?"&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;(Note that 2.2020&amp;nbsp; and 2.20200 from column value and 2.202 from parameter value are same when compared as Numeric values)&lt;/P&gt;
&lt;P&gt;Well. My first advice is not to store multiple values as characters in the single column. Normalization should be applied. If there is no chance to modify the existing structure, there are two ways to compare&lt;/P&gt;
&lt;P&gt;1 Split the column value and parameter value by space and compare each number (This whill be most suggested as usual)&lt;/P&gt;
&lt;P&gt;2 Do not use any split function. Make some changes in the column and parameter to effectively compare the value. &lt;/P&gt;
&lt;P&gt;Ok. We will see how to implement Method 2&lt;/P&gt;
&lt;P&gt;Consider the following set of data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=brush:sql&gt;declare @t table(col varchar(100))
insert into @t
select	'2.2020 30 4.0000' union all
select	'2.2020 30 4.05000' union all
select	'2.20200 30 4.00200' union all
select	'2.2020 300 4.00' union all
select	'2.202000 30 4.0000' 


declare @s varchar(100),@sql varchar(max)
set @s= '2.202 30 4.0' 
set @sql=''
select 
	@sql=@sql+
		'select '''+col+''' as original_col,sum('+replace(col,' ','+')+') as col1,sum('+replace(@s,' ','+')+') as col2,'''+@s+''' as variable_val union all ' 
from @t
select @sql='select original_col as col_val,variable_val from ('+left(@sql,len(@sql)-11)+') as t where col1=col2 and replace(replace(original_col,''0'','' ''),'' '','''')=replace(replace(variable_val,''0'','' ''),'' '','''')'
exec(@sql)
 
&lt;/PRE&gt;Now look at the result &lt;PRE class=brush:sql&gt;col_val            variable_val
------------------ ------------
2.2020 30 4.0000   2.202 30 4.0
2.20200 30 4.00    2.202 30 4.0
&lt;/PRE&gt;If you have any other method please post it in comment's section </description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14825/compare-numbers-stored-as-characters-seperated-by-space.aspx</guid><pubDate>Tue, 15 May 2012 00:00:00 GMT</pubDate></item><item><title>Question of the month May 2012 - How does direct usage of column alias work in ORDER BY clause?</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14381/question-of-the-month-may-2012-how-does-direct-usage-of-column-alias-work-in-order-by-clause.aspx</link><description>&lt;P&gt;Consider the following two statements&lt;/P&gt;
&lt;P&gt;--Query 1 &lt;PRE class=brush:sql&gt;select 
	name, 
	dateadd(day,datediff(day,0,create_date),0) as date_only 
from 
	sys.objects
where 
	date_only&amp;gt;getdate()-100
&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;--Query 2 &lt;PRE class=brush:sql&gt;select 
	name, 
	dateadd(day,datediff(day,0,create_date),0) as date_only 
from 
	sys.objects
order by 
	date_only
&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;While the first query throws an error &lt;STRONG&gt;&lt;FONT color=#ff0000&gt;Invalid column name 'date_only'. &lt;/FONT&gt;&lt;/STRONG&gt;,How does the second query work?</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14381/question-of-the-month-may-2012-how-does-direct-usage-of-column-alias-work-in-order-by-clause.aspx</guid><pubDate>Wed, 09 May 2012 00:00:00 GMT</pubDate></item><item><title>Sum up digits of a number</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14472/sum-up-digits-of-a-number.aspx</link><description>&lt;P&gt;My friend told me that in an interview he was asked to write a code that sums the digits of the number. He asked me if there is a way of doing it without using a WHILE loop. Here are two methods&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Method 1 : Dynamic SQL&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;declare @i int, @sql varchar(8000)
set @i=798273
set @sql=''
select 
	@sql=@sql+substring(ltrim(@i),number,1)+'+' 
from 
	master..spt_values 
where 
	type='p' and number between 1 and len(@i)
select @sql='select '+left(@sql,len(@sql)-1)

exec(@sql+' as sum_of_digits')
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Method 2 : Static SQL&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;declare @i int, @n int
set @i=798273
set @n=0
select 
	@n=@n+substring(ltrim(@i),number,1) 
from 
	master..spt_values 
where 
	type='p' and number between 1 and len(@i)

select @n as sum_of_digits

&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Method 3 : Without using any variables&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=brush:sql&gt;declare @i int
set @i=798273
select 
	sum(substring(ltrim(@i),number,1)*1)
from 
	master..spt_values 
where 
	type='p' and number between 1 and len(@i)

&lt;/PRE&gt;
&lt;P&gt;All the methods would return the following result&lt;/P&gt;&lt;PRE class=brush:sql&gt;sum_of_digits
-------------
36
&lt;/PRE&gt;
&lt;P&gt;Here master..spt_values is a system table which is used as a tally number table. You can use your own table too.&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14472/sum-up-digits-of-a-number.aspx</guid><pubDate>Fri, 04 May 2012 00:00:00 GMT</pubDate></item><item><title>Temporary table and dynamic sql</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14386/temporary-table-and-dynamic-sql.aspx</link><description>&lt;P&gt;One of my collegues told me that while we cannot use a temporary table created inside dynamic sql out of it, in a similar way it is not possible inside dynamic sql to access a temporary table created out of dynamic sql. How many of you think this is true? I immediately showed him the following&amp;nbsp;code to prove him wrong.&lt;/P&gt;&lt;PRE class=brush:sql&gt;create table #t (i int)
GO
exec ('insert into #t(i) select 100')
GO
select i from #t
&lt;/PRE&gt;
&lt;P&gt;The result is 100. As you see it is possible to access the temporary table via dynamic sql in the current session. Ok now the question is "How do I know what objects I can access via dynamic sql?". You can access all the objects that you see from sys.objects. You need to aware of this when using temporary table and dynamic sql.&lt;BR&gt;&lt;BR&gt;You may also be interested to read this post &lt;STRONG&gt;&lt;A href="http://beyondrelational.com/modules/2/blogs/70/posts/10893/scope-of-temporary-tables-across-procedures.aspx"&gt;Scope of temporary tables across procedures&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14386/temporary-table-and-dynamic-sql.aspx</guid><pubDate>Wed, 25 Apr 2012 00:00:00 GMT</pubDate></item><item><title>Computed parameters in Stored Procedure</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14321/computed-parameters-in-stored-procedure.aspx</link><description>Well. You are aware of &lt;A href="http://msdn.microsoft.com/en-us/library/ms191250.aspx"&gt;&lt;STRONG&gt;Computed Columns in SQL Server&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;. &lt;/STRONG&gt;In a similar way&amp;nbsp;you can also use Computed&amp;nbsp;Parameters. Consider the following procedure. &lt;PRE class=brush:sql&gt;Create procedure test
(
	@datetime datetime,
	@date date = @datetime
)
as
	select @datetime as date_with_time, @date as date_only
&lt;/PRE&gt;&lt;PRE&gt;When you execute the procedure you get this result&lt;/PRE&gt;&lt;PRE class=brush:sql&gt;EXEC '2001-10-18 12:45:22.000'&lt;/PRE&gt;&lt;PRE class=brush:sql&gt;date_with_time          date_only
----------------------- ----------
2001-10-18 12:45:22.000 2001-10-18
&lt;/PRE&gt;&lt;PRE&gt;As you see the parameter accepts the value supplied for @datetime and convert it to date datatype. &lt;BR&gt;When you supply value for @date, it will ignore the value of @datetime, the default value for it&lt;/PRE&gt;&lt;PRE class=brush:sql&gt;EXEC '2001-10-18 12:45:22.000','2012-01-22 19:15:12.000'
&lt;/PRE&gt;&lt;PRE class=brush:sql&gt;date_with_time          date_only
----------------------- ----------
2001-10-18 12:45:22.000 2012-01-22
&lt;/PRE&gt;&lt;PRE&gt;However it is not possible to use an expression for the computed paramters &lt;BR&gt;ie @date date=dateadd(day,10,@datetime) will not work. You should be aware of this when you use paramers&lt;BR&gt;this way.&lt;/PRE&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14321/computed-parameters-in-stored-procedure.aspx</guid><pubDate>Fri, 20 Apr 2012 00:00:00 GMT</pubDate></item><item><title>Removing unwanted characters - Part 3</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14280/removing-unwanted-characters-part-3.aspx</link><description>&lt;p&gt;In this series at Part 1 &lt;a target="_blank" href="/blogs/madhivanan/archive/2009/05/11/removing-unwanted-characters.aspx"&gt;&lt;span style="color: #3366cc;"&gt;&lt;strong&gt;Removing unwanted characters&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt; , I posted a method that used a function. In &lt;strong&gt;&lt;a target="_blank" href="/modules/2/blogs/70/posts/10882/removing-unwanted-characters-part-2.aspx"&gt;part 2&lt;/a&gt;&lt;/strong&gt; I posted a method that used Dynamic SQL. &lt;br /&gt;&lt;br /&gt;Here is another improved method that uses Dynamic SQL&lt;/p&gt;
&lt;pre class="brush:sql"&gt;--Create test data

create table #data (data varchar(100))

insert #data 
select 'tes^@&amp;amp;t %stri)-n!g' data union all
select '))aaer***********)' union all
select '&amp;amp;^&amp;amp;&amp;amp;hsdf()' union all
select 'jj&amp;amp;wk' union all
select ')hw*pa' union all
select 'No&amp;amp;@#$53*24,Mai()$n R--!oad'

--Create table that has all set of characters to be removed

create table clean_chars (char_id int identity(1,1),chars char(1))

insert into clean_chars (chars)
select '^' as repl union all 
select ')' union all
select '(' union all
select '&amp;amp;' union all
select '*' union all
select '%' union all
select '@' union all
select '-' union all
select ',' union all
select '#' union all
select '$' union all
select '#' union all
select '!' 

 declare @sql varchar(max), @select varchar(max)
 select @sql='',@select=''
 select @select=@select+'replace(', @sql=@sql+','''+chars+''','''')' from clean_chars

 select @select='select data,'+@select+'data'+@sql+' as cleaned_data from #data' 
 exec(@select)

&lt;/pre&gt;
&lt;p&gt;The result is &lt;/p&gt;
&lt;pre class="brush:sql"&gt;data                                cleaned_data
--------------------------------------------------------
tes^@&amp;amp;t %stri)-n!g                  test string
))aaer***********)                  aaer
&amp;amp;^&amp;amp;&amp;amp;hsdf()                          hsdf
jj&amp;amp;wk                               jjwk
)hw*pa                              hwpa
No&amp;amp;@#$53*24,Mai()$n R--!oad         No5324Main Road


&lt;/pre&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14280/removing-unwanted-characters-part-3.aspx</guid><pubDate>Mon, 16 Apr 2012 01:03:00 GMT</pubDate></item><item><title>Question of the month Apr 2012 - Why does SQL Server allow only one NULL value on unique constraint?</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/14197/question-of-the-month-apr-2012-why-does-sql-server-allow-only-one-null-value-on-unique-constraint.aspx</link><description>&lt;P&gt;Run the following code &lt;/P&gt;&lt;PRE class=brush:sql&gt;	declare @t table(i int unique)
	insert into @t 
	select 1 union all
	select null union all
	select null 
&lt;/PRE&gt;
&lt;P&gt;You will get the following error &lt;/P&gt;&lt;PRE class=brush:sql&gt;Msg 2627, Level 14, State 1, Line 3
Violation of UNIQUE KEY constraint 'UQ__#A989971__3BD019979D26A3BB'. Cannot insert duplicate key in object 'dbo.@t'. The duplicate key value is (&lt;NULL&gt;&lt;/NULL&gt;).
The statement has been terminated.

&lt;/PRE&gt;
&lt;P&gt;But other RDBMSs like ORACLE, MySQL, etc will allow multiple NULL values on a column defined as Unique key. It is because that NULL values cannot be equal to each other&lt;/P&gt;
&lt;P&gt;Why does SQL Server allow only one NULL value on a column that has unique constraint?&lt;/P&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/14197/question-of-the-month-apr-2012-why-does-sql-server-allow-only-one-null-value-on-unique-constraint.aspx</guid><pubDate>Wed, 11 Apr 2012 00:00:00 GMT</pubDate></item><item><title>Storage of table variable</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/13664/storage-of-table-variable.aspx</link><description>&lt;p&gt;Did you know that table variables are stored in the tempdb database for execution scope only?. Ok. Let us run this code &lt;/p&gt;
&lt;pre class="brush:sql"&gt;declare @t table(i int)
select * from tempdb.INFORMATION_SCHEMA.TABLES   
&lt;/pre&gt;
&lt;p&gt;The result is &lt;/p&gt;
&lt;pre class="brush:sql"&gt;TABLE_CATALOG       TABLE_SCHEMA   TABLE_NAME       TABLE_TYPE
---------------------------------------------------------------------
tempdb               dbo           #BAB3F665        BASE TABLE
&lt;/pre&gt;
&lt;p&gt;If your server does not use any temporary tables, you will get the above result only. As you see a table variable is stored in the tempdb database for the execution scope only just like a temporary table. The name is prefixed by #. But unlike a temporary table, the name does not contain underscores. Becauase they are stored in execution scope only, you cannot query the INFORMATION_SCHEMA.TABLES alone to get the table variable information. The following code will not show you any table vaiables &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select * from tempdb.INFORMATION_SCHEMA.TABLES   
&lt;/pre&gt;
&lt;p&gt;How many of you know this?&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/13664/storage-of-table-variable.aspx</guid><pubDate>Mon, 09 Apr 2012 01:27:00 GMT</pubDate></item><item><title>Exploring SSMS - Display line numbers in Query Window</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/13090/exploring-ssms-display-line-numbers-in-query-window.aspx</link><description>&lt;p&gt;As you know I have started a new series on &lt;strong&gt;"Exploring SSMS"&lt;/strong&gt; by which I will be posting some features that are available in SSMS which will be very helping during the development. In this post we will see how to display line number&amp;nbsp;in query window.&lt;/p&gt;
&lt;p&gt;When you write queries in Query window, the line number is not displayed at default. If you want to display line numbers, you can set the following option. &lt;/p&gt;
&lt;p&gt;In the Toolbar, goto &lt;strong&gt;Tools--&amp;gt;Options--&amp;gt;Transact-SQL--&amp;gt;General&lt;/strong&gt;. At the bottom of the window, check the ckeck box labelled &lt;strong&gt;Line Numbers &lt;/strong&gt;and click Ok. You can see your query window with line numbers now.&lt;/p&gt;
&lt;p&gt;Other posts that come under Exploring SSMS&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/06/06/exploring-ssms-enabling-save-changes.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enabling Save Changes&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/04/exploring-ssms-enable-disable-intellisense.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enable/disable intellisense&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/19/exploring-ssms-connecting-to-msdn-forums-or-submitting-your-feedback-to-connect.aspx"&gt;&lt;span style="color: #3366cc;"&gt;&lt;strong&gt;Co&lt;/strong&gt;&lt;strong&gt;nnecting to msdn forums or submitting your feedback to connect&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/29/exploring-ssms-filtering-object-names.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Filtering object names&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/11/exploring-ssms-changing-top-n-rows-values.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Changing Top N rows values&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/08/16/exploring-ssms-copy-results-with-header.aspx"&gt;&lt;span style="color: #3366cc;"&gt;Copy results with header&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2012/02/27/exploring-ssms-hiding-system-databases.aspx"&gt;&lt;span style="color: #3366cc;"&gt;Hiding System databases&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="http://beyondrelational.com/modules/2/blogs/70/posts/11012/exploring-ssms-inserting-code-snippets-for-objects.aspx"&gt;&lt;strong&gt;&lt;span style="color: #003399;"&gt;Inserting Code snippets for Objects&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2012/03/28/exploring-ssms-open-query-window-at-startup.aspx "&gt;Open Query Window at Startup&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/13090/exploring-ssms-display-line-numbers-in-query-window.aspx</guid><pubDate>Fri, 30 Mar 2012 02:06:00 GMT</pubDate></item><item><title>Exploring SSMS - Open Query Window at Startup</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/13042/exploring-ssms-open-query-window-at-startup.aspx</link><description>&lt;p&gt;As you know I have started a new series on &lt;strong&gt;"Exploring SSMS"&lt;/strong&gt; by which I will be posting some features that are available in SSMS which will be very helping during the development. In this post we will see how to open query window at default when opening SSMS.&lt;/p&gt;
&lt;p&gt;When you start SSMS, by default it opens only Object Explorer. You have to open a Query window using a toolbar. If you want to open Query Window along with Object Explorer whenever SSMS is started, you can set the following option. &lt;/p&gt;
&lt;p&gt;In the Toolbar, goto &lt;strong&gt;Tools--&amp;gt;Options--&amp;gt;Startup&lt;/strong&gt;. On the rightside window, choose &lt;strong&gt;Open Object Explorer and Query window &lt;/strong&gt;from the Dropdown and click Ok. Now close the SSMS and start it again. You can see that Query window is automatically opened along with Object Explorer&lt;/p&gt;
&lt;p&gt;Other posts that come under Exploring SSMS&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/06/06/exploring-ssms-enabling-save-changes.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enabling Save Changes&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/04/exploring-ssms-enable-disable-intellisense.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enable/disable intellisense&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/19/exploring-ssms-connecting-to-msdn-forums-or-submitting-your-feedback-to-connect.aspx"&gt;&lt;span style="color: #3366cc;"&gt;&lt;strong&gt;Co&lt;/strong&gt;&lt;strong&gt;nnecting to msdn forums or submitting your feedback to connect&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/29/exploring-ssms-filtering-object-names.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Filtering object names&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/11/exploring-ssms-changing-top-n-rows-values.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Changing Top N rows values&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/08/16/exploring-ssms-copy-results-with-header.aspx"&gt;&lt;span style="color: #3366cc;"&gt;&lt;strong&gt;Copy results with header&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2012/02/27/exploring-ssms-hiding-system-databases.aspx"&gt;&lt;span style="color: #3366cc;"&gt;&lt;strong&gt;Hiding System databases&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/modules/2/blogs/70/posts/11012/exploring-ssms-inserting-code-snippets-for-objects.aspx"&gt;&lt;strong&gt;Exploring SSMS - Inserting Code snippets for Objects&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/13042/exploring-ssms-open-query-window-at-startup.aspx</guid><pubDate>Wed, 28 Mar 2012 02:50:00 GMT</pubDate></item><item><title>Preserving format of procedure when using sp_helptext</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/11950/preserving-format-of-procedure-when-using-sphelptext.aspx</link><description>&lt;p&gt;Often peple ask this question in the forum. "I created a procedure with proper alignment. But when I wanted to alter the procedure, result of sp_helptext did not keep the original alignment. How do I keep the original format?"&lt;/p&gt;
&lt;p&gt;Well. One answer is to make use of Script Stored Procedure --&amp;gt; ALTER TO option from Management Studio. If you want to use sp_helptext system procedure to view and alter, set the result mode of the query window to Text (Press CTRL+T). The text result mode will keep the original alignment&lt;/p&gt;
&lt;p&gt;Consider this simple procedure &lt;/p&gt;
&lt;pre class="brush:sql"&gt;create procedure test
as
	select 
		name,create_date
	from 
		sys.objects
&lt;/pre&gt;
&lt;p&gt;Now set the result mode to Text and run this &lt;/p&gt;
&lt;pre class="brush:sql"&gt;EXEC sp_helptext test
&lt;/pre&gt;
&lt;p&gt;The result will have the origninal formatting with proper alignment. So you need to aware of this when using sp_helptext system proceudre&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/11950/preserving-format-of-procedure-when-using-sphelptext.aspx</guid><pubDate>Wed, 21 Mar 2012 01:15:00 GMT</pubDate></item><item><title>Passing parameters in dynamic procedure</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/11902/passing-parameters-in-dynamic-procedure.aspx</link><description>&lt;p&gt;In this post &lt;strong&gt;&lt;a target="_blank" href="/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx"&gt;Dynamic PIVOT in SQL Server 2005&lt;/a&gt;&lt;/strong&gt;, I have shown a way to dynamically generate the column values with names. I used to get mails frequently from people on how to pass parameters when executing the procedure.&lt;/p&gt;
&lt;p&gt;The following will find total sales made by each employee for each year(from Employees and Orders table from Northwind databases) &lt;/p&gt;
&lt;pre class="brush:sql"&gt;EXEC dynamic_pivot
'SELECT e.lastname, o.OrderDate FROM northwind..Employees as e
INNER JOIN northwind..Orders as o ON (e.EmployeeID=o.EmployeeID) ',
'Year(OrderDate)',
'Count(OrderDate)'

&lt;/pre&gt;
&lt;p&gt;One user mailed me that the following did not work &lt;/p&gt;
&lt;pre class="brush:sql"&gt;DECLARE @year int
SET @year=1984
EXEC dynamic_pivot
'SELECT e.lastname, o.OrderDate FROM northwind..Employees as e
INNER JOIN northwind..Orders as o ON (e.EmployeeID=o.EmployeeID) 
WHERE YEAR(o.OrderDate)=@year',
'Year(OrderDate)',
'Count(OrderDate)'

&lt;/pre&gt;
&lt;p&gt;In the above, @year will not be replaced with it's value. The correct method is to assign it to a variable and use like below &lt;/p&gt;
&lt;pre class="brush:sql"&gt;DECLARE @year int, @sql varchar(max)
SET @year=1984
SET @sql='SELECT e.lastname, o.OrderDate FROM northwind..Employees as e
INNER JOIN northwind..Orders as o ON (e.EmployeeID=o.EmployeeID) 
WHERE YEAR(o.OrderDate)='+cast(@year as varchar(4))

EXEC dynamic_pivot
@sql,
'Year(OrderDate)',
'Count(OrderDate)'

&lt;/pre&gt;
&lt;p&gt;So you need to aware of this when passing parameters to dynamic sql&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/11902/passing-parameters-in-dynamic-procedure.aspx</guid><pubDate>Mon, 19 Mar 2012 01:21:00 GMT</pubDate></item><item><title>Question of the month March 2012 - Select 999'''45'</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/11499/question-of-the-month-march-2012-select-99945.aspx</link><description>&lt;p&gt;Without running this query, can you guess the output? &lt;/p&gt;
&lt;p&gt;Query : &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select 999'''45'
&lt;/pre&gt;
&lt;p&gt;Output : &lt;/p&gt;
&lt;pre class="brush:sql"&gt;Result 1 : Incorrect syntax near '
Result 2 : 999
Result 3 : 999'45
Result 4 : invalid column name 45
&lt;/pre&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/11499/question-of-the-month-march-2012-select-99945.aspx</guid><pubDate>Wed, 14 Mar 2012 01:02:00 GMT</pubDate></item><item><title>Exploring SSMS - Inserting Code snippets for Objects</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/11012/exploring-ssms-inserting-code-snippets-for-objects.aspx</link><description>&lt;p&gt;As you know I have started a new series on &lt;strong&gt;"Exploring SSMS"&lt;/strong&gt; by which I will be posting some features that are available in SSMS which will be very helping during the development. In this post we will see how to insert code template for creating a table, stored procedure, login etc in the&amp;nbsp;SQL Server management studio. &lt;/p&gt;
&lt;p&gt;In the Tool bar, goto &lt;strong&gt;Edit--&amp;gt;IntelliSense--&amp;gt;Insert Snippet&lt;/strong&gt;. You will get an option for Function, table, stored&amp;nbsp;procedure etc.&amp;nbsp;If you want to create a template for table, select &lt;strong&gt;table--&amp;gt;Create table&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;The following code will be added in the query window &lt;/p&gt;
&lt;pre class="brush:sql"&gt;CREATE TABLE dbo.Sample_Table
(
    column_1 int NOT NULL,
    column_2 int NULL
);
&lt;/pre&gt;
&lt;p&gt;If you want to create a code template for Stored procedure with Output parameter, choose &lt;strong&gt;Stored Procedure--&amp;gt;Create procedure &lt;/strong&gt;with OUTPUT parameter. The following code will be added in the query window &lt;/p&gt;
&lt;pre class="brush:sql"&gt;CREATE PROCEDURE dbo.Sample_Procedure 
    @param1 int = 0,
    @param2 int OUTPUT 
AS
    SELECT @param2 = @param2 + @param1 
RETURN 0 
&lt;/pre&gt;
&lt;p&gt;Similarly you can create code templates for other available options.&lt;/p&gt;
&lt;p&gt;Other posts that come under Exploring SSMS&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/06/06/exploring-ssms-enabling-save-changes.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enabling Save Changes&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/04/exploring-ssms-enable-disable-intellisense.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enable/disable intellisense&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/19/exploring-ssms-connecting-to-msdn-forums-or-submitting-your-feedback-to-connect.aspx"&gt;&lt;span style="color: #3366cc;"&gt;&lt;strong&gt;Co&lt;/strong&gt;&lt;strong&gt;nnecting to msdn forums or submitting your feedback to connect&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/29/exploring-ssms-filtering-object-names.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Filtering object names&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/11/exploring-ssms-changing-top-n-rows-values.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Changing Top N rows values&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/08/16/exploring-ssms-copy-results-with-header.aspx"&gt;&lt;span style="color: #3366cc;"&gt;Copy results with header&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2012/02/27/exploring-ssms-hiding-system-databases.aspx"&gt;Hiding System databases&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/11012/exploring-ssms-inserting-code-snippets-for-objects.aspx</guid><pubDate>Wed, 29 Feb 2012 01:28:00 GMT</pubDate></item><item><title>Exploring SSMS - Hiding System databases</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/11011/exploring-ssms-hiding-system-databases.aspx</link><description>&lt;p&gt;As you know I have started a new series on &lt;strong&gt;"Exploring SSMS"&lt;/strong&gt; by which I will be posting some features that are available in SSMS which will be very helping during the development. In this post we will see how to know to hide&amp;nbsp;system databases from the&amp;nbsp;SQL Server management studio. &lt;/p&gt;
&lt;p&gt;In the Tool bar, goto &lt;strong&gt;Tools--&amp;gt;Options&lt;/strong&gt;. Then Under Environment click on &lt;strong&gt;Startup&lt;/strong&gt;. On the right of the windows&amp;nbsp;Check the option labelled as &lt;strong&gt;Hide system objects in Object Explorer&lt;/strong&gt;.&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;If you want to bring them back to object explorer, follow the same procedure and uncheck that option&lt;br /&gt;&lt;br /&gt;Note: You have to restart the SSMS to see the changes.&lt;/p&gt;
&lt;p&gt;Other posts that come under Exploring SSMS&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/06/06/exploring-ssms-enabling-save-changes.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enabling Save Changes&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/04/exploring-ssms-enable-disable-intellisense.aspx"&gt;&lt;strong&gt;&lt;span style="color: #3366cc;"&gt;Enable/disable intellisense&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/19/exploring-ssms-connecting-to-msdn-forums-or-submitting-your-feedback-to-connect.aspx"&gt;&lt;span style="color: #3366cc;"&gt;&lt;strong&gt;Co&lt;/strong&gt;&lt;strong&gt;nnecting to msdn forums or submitting your feedback to connect&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/29/exploring-ssms-filtering-object-names.aspx"&gt;&lt;strong&gt;Filtering object names&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/07/11/exploring-ssms-changing-top-n-rows-values.aspx"&gt;&lt;strong&gt;Changing Top N rows values&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;&lt;a target="_blank" href="/blogs/madhivanan/archive/2011/08/16/exploring-ssms-copy-results-with-header.aspx"&gt;Copy results with header&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/11011/exploring-ssms-hiding-system-databases.aspx</guid><pubDate>Mon, 27 Feb 2012 02:23:00 GMT</pubDate></item><item><title>Fun with Square braces</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/10972/fun-with-square-braces.aspx</link><description>&lt;p&gt;Square braces in SQL Server play a major role in T-SQL programming. When an object name contains a space, special character, etc, the only way to express them is to put them aroud squre braces. Consider that you want to create a table user master (with spaces between user and master), you can use [user master]. &lt;/p&gt;
&lt;p&gt;You can also wrap alias names in square braces &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select 1[74]
&lt;/pre&gt;
&lt;p&gt;The result is &lt;/p&gt;
&lt;pre class="brush:sql"&gt;74
-----------
1
&lt;/pre&gt;
&lt;p&gt;Ok. Now I want to have [74 as column alias. What should I do? I can simply put one more opening square brace like below &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select 1[[74]
&lt;/pre&gt;
&lt;p&gt;which results to &lt;/p&gt;
&lt;pre class="brush:sql"&gt;[74
-----------
1
&lt;/pre&gt;
&lt;p&gt;What if I want to have [74] as column alias? Simply use one more closing square brace. Isn't it? Well the following code &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select 1[[74]]
&lt;/pre&gt;
&lt;p&gt;throws this error &lt;/p&gt;
&lt;pre class="brush:sql"&gt;Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string '[74]'.
&lt;/pre&gt;
&lt;p&gt;Ok. Now can you guess the output of the following statement? &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select 1[[74]]],1[[[[[74]]]]]]]]],1[[[[74]]]]]]]
&lt;/pre&gt;
&lt;p&gt;The output is &lt;/p&gt;
&lt;pre class="brush:sql"&gt;[74]        [[[[74]]]]  [[[74]]]
----------- ----------- -----------
1           1           1
&lt;/pre&gt;
&lt;p&gt;Why are there more number of closing braces than the opening braces used in the statement to produce the output that has same number of opening and closing braces?&lt;/p&gt;
&lt;p&gt;The answer is that the last sqaure brace indicates the end of the square braces wrapping. Other than the last square brace, every double closing braces is replaced as single closing brace in the output alias names. But for opening braces, the output is one less than the total number. The first opening braces indicates the beginning of the wrapping. So you need to be aware of these when using multiple square braces in the column alias.&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/10972/fun-with-square-braces.aspx</guid><pubDate>Mon, 20 Feb 2012 01:13:00 GMT</pubDate></item><item><title>Scope of permanent tables in tempdb database</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/11010/scope-of-permanent-tables-in-tempdb-database.aspx</link><description>&lt;p&gt;As you all know tempdb is responsible of storing all the temporary objects created for a server. One of my co-workers asked me "what is the scope of permanent tables created in the tempdb database?". The answer is it can be accessed via tempdb from various connections just like objects are accessed in other databases. When the server is restarted, the tempdb is recreated and all the objects including permanent tables are dropped.&lt;/p&gt;
&lt;p&gt;Let us analyse these with these examples&lt;/p&gt;
&lt;p&gt;create the following table &lt;/p&gt;
&lt;pre class="brush:sql"&gt;use tempdb
Go
create table test(i int)
&lt;/pre&gt;
&lt;p&gt;You can now access this table from any connection pointing to the server &lt;/p&gt;
&lt;pre class="brush:sql"&gt;Use master
GO
select * from tempdb..t
&lt;/pre&gt;
&lt;p&gt;Ok. Next question is "Does this equal to global temporary table?". Yes. But there is a significant difference between a permanent table and global temporary tables created in the tempdb database. Global temporary table can be accessed from any database without qualifying the databasename whereas permanent table created in the tempdb should be accessed by qualifying the tempdb name when accessed via other database. &lt;/p&gt;
&lt;p&gt;Create a global temporary table &lt;/p&gt;
&lt;pre class="brush:sql"&gt;create table ##test(i int)
&lt;/pre&gt;
&lt;p&gt;You can access this from any database without qualifying the tempdb name as follows &lt;/p&gt;
&lt;pre class="brush:sql"&gt;Use master
GO
select * from ##t
&lt;/pre&gt;
&lt;p&gt;But the following will fail &lt;/p&gt;
&lt;pre class="brush:sql"&gt;Use master
GO
select * from t
&lt;/pre&gt;
&lt;p&gt;Because the object name is searched in the master database and not in tempdb database. But in the case of temporary tables, as long as SQL Server finds a table name prefixed with #, or ## it directly searches them in the tempdb database no matter which database the connection points to. &lt;/p&gt;
&lt;p&gt;So you need to be aware of these points when using permanent table in the tempdb database&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/11010/scope-of-permanent-tables-in-tempdb-database.aspx</guid><pubDate>Tue, 14 Feb 2012 01:04:00 GMT</pubDate></item><item><title>Question of the month February 2012 - Find out problamatic query</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/10999/question-of-the-month-february-2012-find-out-problamatic-query.aspx</link><description>&lt;p&gt;Without running these queries can you find out the query that would throw an error? &lt;/p&gt;
&lt;pre class="brsuh:sql"&gt;1 select 7*-2&amp;amp;.3
2 select 7|2&amp;amp;-3
3 select 7+-(.2)%(+3)
4 select ((7&amp;amp;2%3))
&lt;/pre&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/10999/question-of-the-month-february-2012-find-out-problamatic-query.aspx</guid><pubDate>Wed, 08 Feb 2012 01:03:00 GMT</pubDate></item><item><title>Identity column with decimal datatype</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/10969/identity-column-with-decimal-datatype.aspx</link><description>&lt;p&gt;One of the members in the forum asked about using decimal datatype in identity column. The question was "Is decimal point allowed in the identity column?" Ok. The identity column can never have any decimal points. It is a whole number. The decimal datatype can be used to have a bigger number in the identity column as decimal can have maximum of 38 digits.&lt;/p&gt;
&lt;p&gt;The following are the code to create an identity column with decimal datatype &lt;/p&gt;
&lt;p&gt;1 Specify scale as 0 &lt;/p&gt;
&lt;pre class="brush:sql"&gt;declare @t table(i decimal(38,0) identity(1,1))
insert into @t default values
select * from @t
&lt;/pre&gt;
&lt;p&gt;2 Omit scale part &lt;/p&gt;
&lt;pre class="brush:sql"&gt;declare @t table(i decimal(38) identity(1,1))
insert into @t default values
select * from @t
&lt;/pre&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/10969/identity-column-with-decimal-datatype.aspx</guid><pubDate>Mon, 30 Jan 2012 01:14:00 GMT</pubDate></item><item><title>Knowing minimum timestamp value for a database</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/10977/knowing-minimum-timestamp-value-for-a-database.aspx</link><description>&lt;p&gt;When a datatype timestamp or rowversion is used, it generates unique value whenever a row is added or updated in a table. It is one of the ways to generate auto-generated values not only for insertion but for updation too. If you want to know the minimum active rowvertion number for a database, you can make use of system function MIN_ACTIVE_ROWVERSION() &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select  MIN_ACTIVE_ROWVERSION()
&lt;/pre&gt;
&lt;p&gt;The above query returns the minimum rowversion number available for the current database.&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/10977/knowing-minimum-timestamp-value-for-a-database.aspx</guid><pubDate>Wed, 18 Jan 2012 04:13:00 GMT</pubDate></item><item><title>Question of the month January 2012 - Datatype of NULL</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/10996/question-of-the-month-january-2012-datatype-of-null.aspx</link><description>&lt;p&gt;Without running the following code , can you guess the datatype of the column t? &lt;/p&gt;
&lt;pre class="brush:sql"&gt;select null+getdate()+772.67 as t into #t5
&lt;/pre&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/10996/question-of-the-month-january-2012-datatype-of-null.aspx</guid><pubDate>Wed, 11 Jan 2012 01:25:00 GMT</pubDate></item><item><title>@@TRANCOUNT is always incremented in a trigger</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/10978/trancount-is-always-incremented-in-a-trigger.aspx</link><description>&lt;p&gt;The system variable @@TRANCOUNT is used to get the number of transactions that are active. Consider the following code &lt;/p&gt;
&lt;pre class="brush:sql"&gt;begin transaction
select 3
select @@TRANCOUNT 
commit transaction

&lt;/pre&gt;
&lt;p&gt;The result of @@TRANCOUNT is 1. Consider the following code. &lt;/p&gt;
&lt;pre class="brush:sql"&gt;begin transaction
select 3
begin transaction
select 456
select @@TRANCOUNT 
commit transaction
commit transaction


&lt;/pre&gt;
&lt;p&gt;The result of @@TRANCOUNT is 2. &lt;/p&gt;
&lt;p&gt;So whenever there is a transaction the variable @@TRANCOUNT gets incrementedx by 1. In an Auto commit mode if you dont use a transaction, @@TRANCOUNT will never gets incremented. But this variable gets incremented always in a trigger.&lt;/p&gt;
&lt;p&gt;This is what BOL specifies &lt;/p&gt;
&lt;p&gt;@@TRANCOUNT is incremented by one when entering a trigger, even when in autocommit mode. (The system treats a trigger as an implied nested transaction.)&lt;/p&gt;
&lt;p&gt;So you need to be aware of this and use @@TRANCOUNT effectively.&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/10978/trancount-is-always-incremented-in-a-trigger.aspx</guid><pubDate>Mon, 09 Jan 2012 01:24:00 GMT</pubDate></item><item><title>Just Learned posts for the month of December 2011</title><link>http://beyondrelational.com/modules/2/blogs/70/posts/11009/just-learned-posts-for-the-month-of-december-2011.aspx</link><description>&lt;p&gt;As I have informed you earlier in &lt;a target="_blank" href="http://beyondrelational.com/blogs/madhivanan/archive/2011/06/01/just-learned-section-at-beyondrelational-com.aspx"&gt;&lt;strong&gt;this post&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;,&lt;/strong&gt; there are some interesting tips I have contributed in December 2011. You may &lt;span style="color: #1c7dff;"&gt;find&lt;/span&gt; them interesting if you follow them. The following are some of my tips I posted there&lt;/p&gt;
&lt;p&gt;Most Learned Posts of all time&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://beyondrelational.com/justlearned/posts/83/you-can-drop-multiple-tables-using-single-drop-statement.aspx"&gt;You can drop multiple tables using single DROP statement&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="http://beyondrelational.com/justlearned/posts/286/google-is-also-a-caculator.aspx"&gt;Google is also a calculator&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="http://beyondrelational.com/justlearned/posts/37/opening-msdn-forum-from-ssms.aspx"&gt;SSMS Allows you to ask a question in the MSDN forum directly from SSMS&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="http://beyondrelational.com/justlearned/posts/556/using-partition-switching-you-can-move-millions-of-rows-from-one-table-to-another-in-less-than-a-second.aspx"&gt;Using Partition Switching you can move millions of rows from one table to another in less than a second&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="http://beyondrelational.com/justlearned/posts/103/semicolon-can-be-used-to-execute-a-procedure.aspx"&gt;Semicolon can be used to execute a procedure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Just Learned Posts for the month&amp;nbsp;of December 2011&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="/justlearned/posts/895/sql-server-use-shiftdel-to-delete-entire-line-in-query-window.aspx"&gt;Use Shift+DEL to delete entire line in Query window&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://beyondrelational.com/modules/2/blogs/70/posts/11009/just-learned-posts-for-the-month-of-december-2011.aspx</guid><pubDate>Mon, 02 Jan 2012 02:28:00 GMT</pubDate></item></channel></rss>

