Retrieving id of inserted record: What to use @@IDENTITY or SCOPE_IDENTITY() or OUTPUT

Hi guys,
This seems very basic information but need to know properly.

I need to find out or have the id of the records which I inserted in table.

This requirement seems very simple but there could be various cases where you would not get the correct id just by using @@IDENTITY function.

Think of the case where you are inserting a record in table A and there is a trigger which fires as soon as there is a insert in table A which insert a record in table B. so in such case @@IDENTITY wont give you the correct id/pointer of inserted record.

So to deal with this issue you can use SCOPE_IDENTITY(). You will always get the last value you have inserted in table. However, it is noticed that sometimes in some scenarios SCOPE_IDENTITY() does not promise the correctness of results. May be due to parallelism or multiple inserts or bulk inserts in table(s). E.g. when you do … Insert Into Select <columns> from Table

Well, Microsoft recommends that “You do not use either of these functions in your queries when parallel plans are involved as they are not always reliable. Instead use the OUTPUT clause of INSERT statement to retrieve the identity value“.

Check out MS articles:;en-US;2019779

I hope this will help you somewhere.
Thanks, Khilit

bigatorFebruary 6, 2013 · bigatorKhilitchandra Prajapati · bigatorNo Comments
bigatorTags: , , , , , ,  · Posted in: Business Intelligence, Free, General, Interview QA, Quick Fix, Quick Tips, Script, SQL Server, SQL Server 2012, SQLServerPedia, T-SQL, Training, Tutorial

The Story of Precision, Scale, and Length in SQL Server

Hi guys,

Did you ever faced issues with BIG mathematical figures – related to either overflow or any  other arithmetic errors. This may be applicable to SQL arithmetic operations or arithmetic  operations you do with SQL table in SSIS etc.

Well, check 1 more time, if you have any issues in your database design related to column  data type which stores the BIG numbers.

I ran into this issue couple of times, and reason behind this issue was same all the time. So  decided to do a quick post. And that reason is “Improper or insufficient precision, scale and length defined for storing Decimals and Numeric values in table“.

I wanted to describe this with an example but there is already a very nice explanation by MSDN  on this topic. Check out:

You will notice in this article that, how any arithmetic operation will affect size and space  allocation of the resultant value during mathematical operation. You should use following shown table for defining and designing tables in such a way that can  handle BIG mathematical figures during operations.

From MSDN, for your quick view:


Result precision

Result scale *

e1 + e2 max(s1, s2) + max(p1-s1, p2-s2) + 1 max(s1, s2)
e1 – e2 max(s1, s2) + max(p1-s1, p2-s2) + 1 max(s1, s2)
e1 * e2 p1 + p2 + 1 s1 + s2
e1 / e2 p1 – s1 + s2 + max(6, s1 + p2 + 1) max(6, s1 + p2 + 1)
e1 { UNION | EXCEPT | INTERSECT } e2 max(s1, s2) + max(p1-s1, p2-s2) max(s1, s2)
e1 % e2 min(p1-s1, p2 -s2) + max( s1,s2 ) max(s1, s2)

* The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, the corresponding scale is reduced to prevent the integral part of a result from being truncated.

Important Note: Don’t forget to check for your SQL Server Version.

I hope you will find this informative.
Thanks, Khilit

bigatorJanuary 28, 2013 · bigatorKhilitchandra Prajapati · bigatorOne Comment
bigatorTags: , , , , ,  · Posted in: Business Intelligence, Free, General, Interview QA, Quick Fix, Quick Tips, Script, SQL Server, SQL Server 2012, SQLServerPedia, SSAS, SSIS, SSRS, T-SQL, Tutorial

Tracking Down Ghost Characters: WHERE Clause Does Not Work Properly In T-SQL Query

Hi guys,
I would like to share an experience with you when I was working on 1 SSIS related issue.

Scenario was:
I have to exclude some records from Table A by matching some keys of Table B.

 Table A

Year Month CustomerCode <Extra Columns>
2012 JAN CX1000  
2012 JAN CX2000  
2012 JAN CD3000  


 Table B

Year Month RecCustomerCode <Extra Columns>
2012 JAN CX1000  
2012 JAN CX7000  
2012 JAN CD8000  


 What is expected was – Table A’s following records:

Year Month CustomerCode <Extra Columns>
2012 JAN CX2000  
2012 JAN CD3000  

  Read the rest of this post »

bigatorJanuary 25, 2013 · bigatorKhilitchandra Prajapati · bigatorNo Comments
bigatorTags: , , , , , , , , ,  · Posted in: Business Intelligence, Free, General, Interview QA, Quick Fix, Quick Tips, Script, SQL Server, SQL Server 2012, SSIS, T-SQL, Tutorial

MSSQL: Find total records of each Table in given Database

hi guys,
i wanted to do a quick post on how you can find total number of records in each table of the database.

here is the script you can use:

USE <Your Database Name>



Note: Customize this query according to your needs 🙂

Thanks, Khilit

bigatorJanuary 23, 2013 · bigatorKhilitchandra Prajapati · bigatorOne Comment
bigatorTags: ,  · Posted in: Business Intelligence, General, Interview QA, SQL Server, SQL Server 2012, SQLServerPedia, SSAS, SSIS, SSRS

Microsoft SSAS Solution: Cube Design Considerations

Hi guys,
today i read James Serra’ post – whether 1 single BIG cube is good as comapred to multiple small cubes. Check out the advantages and disadvantages with both design approaches. he made a pretty nifty list of both of these.

i would also recommend you to read this post.
here is the link:

i hope you also find this interesting.
thanks, khilit

bigatorJanuary 16, 2013 · bigatorKhilitchandra Prajapati · bigatorNo Comments
bigatorTags: , , ,  · Posted in: Business Intelligence, General, Interview QA, Quick Fix, SQL Server, SQL Server 2012, SSAS

User ‘Domain\User’ does not have required permissions. Verify that sufficient permissions have been granted and Windows User Account Control (UAC) restrictions have been addressed.

Hi guys,
its seems like this issue have been faced by many prople. i have checked the solutions on web and found that not all answers contains the complete solution. so decided to put 1 complete solution here.

in most of the places, you will find answers like… Run IE as Administrator -> Open Report Manager site -> Add your user in “System Role Assignment” (settings) etc.

But there is tini-tiny step you have to do before you run your IE as Administrator.

  • Open your IE -> Tool -> Internet Options.
  • Security tab -> Local intranet -> Sites -> Advanced -> Add your root level site here.
  • Advanced tab -> Make sure you have checked (selected) the item “Enable Integrated Windows Authentication*” under Security category.

thats it.

now are you ready to follow … Run IE as Administrator etc.
Here is the what you need to do now:

i hope this will help you somewhere.
thanks, khilit

bigatorJanuary 16, 2013 · bigatorKhilitchandra Prajapati · bigatorNo Comments
bigatorTags: , , , , ,  · Posted in: Business Intelligence, General, Interview QA, Quick Fix, SQL Server, SQL Server 2012, SSRS

Quick Introduction – What is FileTable in SQL Server 2012 ?

Hi guys,
With the release of SQL Server 2012, couple of Programmability enhancements are also introduced. One of the cool feature is “FileTable”.

So, what is FileTable and Why do we need it?

Applications typically store data within a relational database. But as we know that different applications stores their data in their own formats which could be unstructured formats for other applications and database, e.g. word or excel documents, media files, XML files etc.

Unstructured data usually resides on a file server (File System) and not directly in a relational database such as SQL Server. (Because if we do so, then it would increase the size of database)

So, it becomes challenging for us to manage structured and unstructured data across these systems/platforms as well as to keep them in sync.

FileTable feature which is a new capability in SQL Server 2012 is a solution for these challenges.

It builds on FILESTREAM technology that was first introduced with SQL Server 2008. FileTable offers organizations Windows file namespace support and application compatibility with the file data stored in SQL Server.

As an added bonus, when applications are allowed to integrate storage and data management within SQL Server, fulltext
and semantic search is achievable over unstructured and structured data.

You can find more details here :

Thanks, Khilit

bigatorDecember 6, 2012 · bigatorKhilitchandra Prajapati · bigatorNo Comments
bigatorPosted in: Uncategorized

Microsoft Business Intelligence at a Glance Poster – FREE

hi guys,

Download this FREE poster and find-out the Tools and Technologies Microsoft offers under BI (Business Intelligence) umbrella.
Here is the direct link:

Thanks, Khilit

bigatorDecember 5, 2012 · bigatorKhilitchandra Prajapati · bigatorNo Comments
bigatorPosted in: Uncategorized

SQL Server User Group Event on 4th Oct 2012, Singapore

Hello friends,
how are you doing?

There is an event (SQL User Group, Singapore) on 4th October 2012. Following is the detail about the event. Send an email to “Chen Liang <>” with your name, working place and contact number for reservation of your seat. There is no charge for all members of SQL Server Singapore User Group.

You can become the member of this group by joining this group:


SQL Server Integration Services 2012 Unplugged


4th Oct 18:30 – 21:00


One Marina Boulevard, 22CF-15


Dr. Wee Hyong, Tok

Dr. Wee Hyong is a Senior Program Manager on the SQL Server Integration Services (SSIS) team. Since joining the team in 2008, he has been with the SSIS team, and has worked on all areas of the product.  Prior to joining Microsoft, Wee Hyong is a Microsoft Most Valuable Professional (MVP), and frequently presents at various technology conferences.

Topic Introduction

In this session, you will learn about the new features of Microsoft SQL Server Integration Services in SQL Server 2012. Using customer scenarios, we show the many improvements that have been made to increase developer productivity. You will learn how SSIS 2012 makes it easier for you to deploy, configure, manage and monitor SSIS packages. If you’re wondering what’s in store for SSIS, you won’t want to miss this session!

I hope to see you there.
Thanks, Khilit


bigatorSeptember 19, 2012 · bigatorKhilitchandra Prajapati · bigatorNo Comments
bigatorTags: , , ,  · Posted in: Business Intelligence, Free, General, Microsoft Event, SQL Server, SSIS

What is OLAP Database ? What is FASMI?

Hi guys,
i was reading an article and came across this term “FASMI“. i have done a little bit of RnD to find out its head & tail. This is what it means:

FASMI is an acronym of “Fast Analysis of Shared Multidimensional Information“.

A database when called “OLAP Database” if it satisfies following FASMI rules.

1. Fast Analysis (FA):
Data retrieval should be less than 5 seconds. Should support any business scenarios for any type of analysis. The structure should support such flexibility that new calculations can be easily and quickly defined.

Read the rest of this post »

bigatorSeptember 7, 2012 · bigatorKhilitchandra Prajapati · bigator3 Comments
bigatorTags: , , , , , ,  · Posted in: Business Intelligence, Data Mining, DMX, General, Interview QA, MDX, Pivot Table, Power Pivot, Query Tuning, SQL Server, SQL Server 2012, SSAS, Training, Tutorial