tag:blogger.com,1999:blog-50982084256139025822024-03-14T01:37:09.452-07:00Tips and Tricks for SQL Server DevelopersSQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.comBlogger72125tag:blogger.com,1999:blog-5098208425613902582.post-90469116051441650952019-10-30T08:15:00.000-07:002019-11-17T19:10:11.895-08:00Introduction to Memory-Optimized Tables<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Memory-optimized tables are fully durable by
default, and transactions on memory-optimized tables are fully atomic,
consistent, isolated, and durable (ACID)</span>.<o:p></o:p></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.7pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l1 level1 lfo1; text-indent: -17.85pt;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt "Times New Roman";"> </span></span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Memory-optimized tables
reside in memory.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.7pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l1 level1 lfo1; text-indent: -17.85pt;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt "Times New Roman";"> </span></span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Rows in the table are
read from and written to memory. The entire table resides in memory.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.7pt; margin-right: 0in; margin-top: 3.0pt; mso-list: l1 level1 lfo1; text-indent: -17.85pt;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt "Times New Roman";"> </span></span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">A second copy of the
table data is maintained on disk, but only for durability purposes.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">In-Memory OLTP is integrated with SQL Server
to provide a seamless experience in all areas such as development, deployment,
manageability, and supportability.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Rows in memory-optimized tables are versioned
so each row in the table potentially has multiple versions. Row versioning is
used to allow concurrent reads and writes on the same row.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">The following figure illustrates
multi-versioning. The table has three rows: R1, R2, and R3. R1 has three
versions, R2 has two versions, and R3 has four versions.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmWsjmnMfph2JTrk-2hUWlzG5Uf2jnecYxZ8OCLB3Aah4Ef3c0r-aP0QxTByjaUKbYS7WuB-dATpDIfw7sdXplp2WpiJ39zwRS8TRKBnMfcvvcIDCM7pX2qDSa8npZHKrbEDfB5XMzJbE/s1600/Row+Versioning.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="242" data-original-width="317" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmWsjmnMfph2JTrk-2hUWlzG5Uf2jnecYxZ8OCLB3Aah4Ef3c0r-aP0QxTByjaUKbYS7WuB-dATpDIfw7sdXplp2WpiJ39zwRS8TRKBnMfcvvcIDCM7pX2qDSa8npZHKrbEDfB5XMzJbE/s1600/Row+Versioning.png" /></a></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Note: Different versions of the same row do
not necessarily occupy consecutive memory locations. Instead, it can be
dispersed throughout the table data structure.<o:p></o:p></span></div>
<div>
<br /></div>
<div>
<div class="MsoNormal">
<b><span lang="EN" style="font-size: 13.0pt; mso-ansi-language: EN; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin;">Durability<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Memory-optimized tables are fully durable by default, and they are fully
atomic, consistent, isolated, and durable (ACID) (like transactions disk-based
tables).<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">In-Memory OLTP supports durable tables with transaction durability delayed.
Delayed durable transactions are saved to disk soon after the transaction has
committed. <o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Besides the default durable memory-optimized tables, SQL Server also
supports non-durable memory-optimized tables, which are not logged, and their
data is not persisted on disk. This means that transactions on these tables do
not require any disk IO, but the data will not be recovered if there is a
server crash or failover.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Durability options:<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">SCHEMA_AND_DATA</span></b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> (<i>default</i>): This option ensures that <b>data
is recovered to the Memory-Optimized table</b> when SQL Server is restarted or
is recovering from a crash.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">SCHEMA_ONLY</span></b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">: Like Tempdb data, the SCHEMA_ONLY bound <b>Memory-Optimized
table will be truncated</b> if/when SQL Server is restarted or is recovering
from a crash, but unlike the tables in Tempdb, the Memory-Optimized table will
be re-created as a blank table at the end of the restart/recovery operation<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="font-size: 13.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin;">Accessing Data in Memory-Optimized Tables</span></b><b><span lang="EN" style="font-size: 13.0pt; mso-ansi-language: EN; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Data in
memory-optimized tables is accessed in two ways:<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Through interpreted Transact-SQL (outside of a natively-compiled stored
procedure). These Transact-SQL statements may be either inside interpreted
stored procedures or they may be ad-hoc Transact-SQL statements.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Through natively compiled stored procedures.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="font-size: 13.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin;">Performance and Scalability<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">The following
factors will affect the performance gains that can be achieved with In-Memory
OLTP:<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Communication</span></b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> - an application with many calls to short
stored procedures may see a smaller performance gain compared to an application
with fewer calls and more functionality implemented in each stored procedure.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Transact-SQL Execution</span></b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> - In-Memory OLTP achieves the best
performance when using natively compiled stored procedures rather than
interpreted stored procedures or query execution. Stored procedures that
execute other stored procedures cannot be natively compiled, but there can be a
benefit to accessing memory-optimized tables from such stored procedures.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Range Scan Vs Point Lookup</span></b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> - Memory-optimized nonclustered indexes
support range scans and ordered scans. For point lookups, memory-optimized hash
indexes have better performance than memory-optimized nonclustered indexes.
Memory-optimized nonclustered indexes have better performance than disk-based
indexes. Index operations are not logged and they exist only in memory.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .75in; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Concurrency</span></b><span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> - Applications whose performance is affected
by engine-level concurrency, such as latch contention or blocking, improves
significantly when the application moves to In-Memory OLTP.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="font-size: 13.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin;">Creating Memory-Optimized Tables<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Assumption
for below exercise is that you have SQL server 2014 installed. Below examples will
be using TestDB database for this exercise.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><b><span lang="EN">Step 1: Create Memory Optimized File Group</span></b></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span lang="EN-IN" style="color: blue; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: blue;">USE</span><span lang="EN-IN">
[master]<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: blue;">GO</span><span lang="EN-IN"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: blue;">ALTER</span><span lang="EN-IN"> <span style="color: blue;">DATABASE</span> [TestDB] <span style="color: blue;">ADD</span>
<span style="color: blue;">FILEGROUP</span> [fgMOD] <span style="color: magenta;">CONTAINS</span>
MEMORY_OPTIMIZED_DATA<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: blue;">GO</span><span lang="EN-IN"><o:p></o:p></span></span></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: blue; font-family: Calibri, sans-serif;">ALTER</span><span lang="EN-IN" style="font-family: Calibri, sans-serif;"> <span style="color: blue;">DATABASE</span> [TestDB] <span style="color: blue;">ADD</span>
<span style="color: blue;">FILE </span><span style="color: grey;">(</span> NAME <span style="color: grey;">=</span> <span style="color: red;">N'SQL2014_MOD'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\MSSQL\SQL2014_MOD'</span>
<span style="color: grey;">)</span> <span style="color: blue;">TO</span> <span style="color: blue;">FILEGROUP</span> [fgMOD]</span></span></div>
<div class="MsoListParagraph">
<span lang="EN-IN" style="font-size: 9.5pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoListParagraph">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoListParagraph">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">You can make changes in file name or path as per your requirement.<o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<br /></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]--><span lang="EN" style="font-family: Symbol; mso-ansi-language: EN; mso-bidi-font-family: Symbol; mso-bidi-font-weight: bold; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><b><span lang="EN">Step 2: Create Memory Optimized Table<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin: 0in; text-indent: .5in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Creating an In-Memory (Memory-Optimized) tables in SQL Server is straight
forward.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: blue;">CREATE</span><span lang="EN-IN"> <span style="color: blue;">TABLE</span> dbo<span style="color: grey;">.</span>MemoryOptimizedTable<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: grey;">(</span><span lang="EN-IN"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span lang="EN-IN"><span style="font-size: xx-small;">tableId <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span>
<span style="color: grey;">NULL</span> <span style="color: blue;">PRIMARY</span> <span style="color: blue;">KEY</span> <span style="color: blue;">NONCLUSTERED</span> <span style="color: blue;">HASH</span> <span style="color: blue;">WITH </span><span style="color: grey;">(</span><span style="color: blue;">bucket_count</span> <span style="color: grey;">=</span> 2000000<span style="color: grey;">)</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: grey;">,</span><span lang="EN-IN">naturalId <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL</span> <span style="color: blue;">INDEX</span>
NC_MemoryOptimizedTable_NaturalId <span style="color: blue;">NONCLUSTERED</span> <span style="color: blue;">HASH</span> <span style="color: blue;">WITH </span><span style="color: grey;">(</span><span style="color: blue;">bucket_count</span> <span style="color: grey;">=</span> 1000000<span style="color: grey;">)</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: grey;">,</span><span lang="EN-IN">value <span style="color: blue;">NVARCHAR</span><span style="color: grey;">(</span>100<span style="color: grey;">)</span> <span style="color: grey;">NULL</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: grey;">)</span><span lang="EN-IN"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-size: xx-small;"><span lang="EN-IN" style="color: blue;">WITH </span><span lang="EN-IN" style="color: grey;">(</span><span lang="EN-IN" style="color: blue;">MEMORY_OPTIMIZED</span><span lang="EN-IN"> <span style="color: grey;">=</span> <span style="color: blue;">ON</span><span style="color: grey;">,</span> <span style="color: blue;">DURABILITY</span> <span style="color: grey;">=</span>
SCHEMA_AND_DATA<span style="color: grey;">)</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: blue; font-family: Calibri, sans-serif;"><span style="font-size: xx-small;">GO</span></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="font-size: 13.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin;">Indexing Memory-Optimized Tables<o:p></o:p></span></b></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Memory
Optimized tables support two types of indexes:<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l3 level1 lfo3; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b>Non-Clustered Hash
Index</b>:
This is a <b>memory optimized</b> index, it does not support inequality
operators as well as sort-order matching operations.<o:p></o:p></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l3 level1 lfo3; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b>Non-Clustered Index</b>: This is a <b>disk
based</b> index, fully supports all normal index operations.<o:p></o:p></div>
<div class="MsoListParagraph" style="margin-left: .75in;">
<br /></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<span lang="EN" style="font-family: "Calibri",sans-serif; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">There are a
few stipulations for creating indexes on Memory-Optimized tables:<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l2 level1 lfo4; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b>Only 8 indexes</b> are allowed on a
Memory Optimized table<o:p></o:p></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l2 level1 lfo4; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b>Indexes cannot be
added to a Memory Optimized table</b>, instead the table has to be dropped and
re-created with the new index.<o:p></o:p></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l2 level1 lfo4; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b>Primary Key is a
requirement</b> for Memory Optimized tables.<o:p></o:p></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l2 level1 lfo4; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b>All indexes are
covering</b>, which means they include all columns in a table.<o:p></o:p></div>
<div class="MsoListParagraph" style="margin-left: .75in; mso-list: l2 level1 lfo4; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-fareast-language: EN-IN;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><b>Indexes reference
the (hashed) row directly</b>, rather than referencing the Primary Key.<o:p></o:p></div>
<div class="MsoListParagraph" style="margin-left: .75in;">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="font-size: 13.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin;">Querying Memory-Optimized Tables<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Calibri, sans-serif; font-size: 12pt;">Memory-Optimized
tables supports access through T-SQL and Natively Compiled Stored Procedures.
Generally, you will require a SNAPSHOT isolation level or higher in order to
access a Memory-Optimized table.</span> </div>
<div class="MsoNormal">
<br /></div>
</div>
<div>
References:</div>
<div>
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li>docs.microsoft.com</li>
<li>thinknook.com</li>
</ul>
</div>
</div>
SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-21459889800944591582017-03-15T09:00:00.000-07:002017-03-21T02:54:20.494-07:00Slowly Changing Dimensions<div dir="ltr" style="text-align: left;" trbidi="on">
I was planning to explain <strong>Slowly Changing Dimension</strong> (<strong>SCDs</strong>) since long time so this article is all about SCD(s).<br />
<br />
<strong>Slowly Changing Dimensions (SCDs)</strong> are those dimensions that have data that may change slowly over the period, rather than changing on a time-based regular schedule. For example, a dimension in your Sales database tracks the sales information of your company's salespeople. Creating sales reports are easy until a salesperson is transferred from one department (office) to another. How do you handle such a change in your sales dimension?<br />
<br />
Here is a scenario: <br />
<em><span style="color: #134f5c;">An Employee "XXX" belongs to Department D1 from DateOfJoining till 01/01/2008, so whatever sales made by this employee added to department D1. After couple of years, that employee moved in to department D2 on 01/01/2010. Now all his sales contribution should be added to D2 from 01/01/2010 onwards and the old sales should still belong to D1</span></em>.<br />
<br />
<br />
<strong>Types of SCDs:</strong><br />
There are different types of management methodologies referred as Type 0 through 6.<br />
<span style="color: blue;"><br /></span>
<span style="color: blue;"><strong>SCD Type 0</strong>:</span><br />
The Type 0 method is a passive approach to managing dimension value changes, in which no action is taken. Values remain as they were at the time the dimension record was first entered.Type 0 provides the least control or no control over managing a slowly changing dimension.<br />
<br />
<em>The most common slowly changing dimensions are Types 1, 2, and 3.</em><br />
<br />
<strong><span style="color: blue;">SCD Type 1:</span></strong><br />
This methodology overwrites old data with new data and therefore does not track historical data at all. <br />
<br />
Here is an example of a database table that keeps customer's email information:<br />
<table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.8pt;" valign="top" width="100">
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">CustomerID</span></b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">CustomerName</span></b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 171.7pt;" valign="top" width="229">
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Email</span></b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.8pt;" valign="top" width="100">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Cust101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 171.7pt;" valign="top" width="229">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">abc@xyz.com<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.8pt;" valign="top" width="100">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Cust102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 171.7pt;" valign="top" width="229">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">pqr@xyz.com<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />If Cust101 email changes from abc@xyz.com to def@xyz.com then we need simple update statement to overwrite the old value with new one.<br />
Here is how table will look after update command:<br />
<table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.8pt;" valign="top" width="100">
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">CustomerID</span></b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">CustomerName</span></b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 171.7pt;" valign="top" width="229">
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Email</span></b><span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.8pt;" valign="top" width="100">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Cust101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 171.7pt;" valign="top" width="229">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">def@xyz.com<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.8pt;" valign="top" width="100">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Cust102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt; width: 171.7pt;" valign="top" width="229">
<div class="MsoNormal">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">pqr@xyz.com<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />The main disadvantage to Type 1 SCDs is that there is no historical record kept in the data warehouse. But an advantage to Type 1 SCDs is that they are very easy to maintain.<br />
<br />
<strong><span style="color: blue;">SCD Type 2:</span></strong> <br />
The Type 2 SCD tracks historical data by creating multiple records in the dimensional tables with separate surrogate keys. With Type 2, we have unlimited history preservation as a new record is inserted each time a change is made.<br />
<br />
Lets consider above example again. We need to maintain history of email address as well, in that case, we need two more columns (FromDate & ToDate).<br />
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">CustomerID<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">CustomerName<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">Email<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">FromDate<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">ToDate<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">Cust101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">abc@xyz.com<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">2011-01-01<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">9999-12-31<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">Cust102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">pqr@xyz.com<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">2014-10-25<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">9999-12-31<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
If Cust101 email changes from abc@xyz.com to def@xyz.com on 2017-02-15, then we need to insert a new record and update the ToDate of previous record<br />
Here is how table will look after update command:<br />
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">CustomerID<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">CustomerName<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">Email<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">FromDate<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">ToDate<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">Cust101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">abc@xyz.com<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">2011-01-01<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">2017-02-14<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">Cust101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">abc@xyz.com<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">2017-02-15<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">9999-12-31<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">Cust102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">pqr@xyz.com<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">2014-10-25<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">9999-12-31<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<b><span style="color: blue;">SCD Type 3:</span></b><br />
The Type 3 method tracks changes using separate columns. Whereas Type 2 had unlimited history preservation, Type 3 has limited history preservation, as it’s limited to the number of columns we designate for storing historical data. Where the original table structure in Type 1 and Type 2 was very similar, Type 3 will add additional columns to the tables:<br />
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">CustomerID<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">CustomerName<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">OriginalEmail<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">FromDate<o:p></o:p></span></b></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<b><span style="font-size: 12.0pt;">CurrentEmail<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">Cust101<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">abc@xyz.com<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">2017-02-15<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">abc@xyz.com<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 74.4pt;" valign="top" width="99">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" valign="top" width="124">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">Cust102<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">pqr@xyz.com<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">NULL<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 78.2pt;" valign="top" width="104">
<div class="MsoNormal">
<span style="font-size: 12.0pt;">NULL<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br /><div>
Type 3 is less common because it involves changing the physical tables and is not scalable.</div>
<div>
<br /></div>
<div>
<span style="font-size: xx-small;">Reference: MSDN</span></div>
</div>
SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-71823206127065593712016-03-31T19:00:00.000-07:002016-04-04T08:10:43.939-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoBodyText">
<span style="color: #333333; font-family: Segoe UI, sans-serif; font-size: large;"><b>Analysis Services connectivity issue from Remote Server</b></span></div>
<div class="MsoBodyText">
<span style="color: #333333; font-family: Segoe UI, sans-serif;"><br /></span></div>
<div class="MsoBodyText">
<span style="color: #333333; font-family: "Segoe UI",sans-serif;"><b>Problem:
</b>I was recently working with one of my colleagues to setup a new server in Azure. He installed
all the SQL server components. When we tried to connect OLAP cubes from another
local or remote server, we were facing connectivity issue with the following error
message:<o:p></o:p></span></div>
<div class="MsoBodyText">
<span style="color: #333333; font-family: "Segoe UI",sans-serif;">“</span><span style="color: red; font-family: "Segoe UI",sans-serif;">A connection attempt failed
because the connected party did not properly respond after a period of time, or
established connection failed because connection host has failed to respond xxx.xxx.xxx.xxx:xxxx(System).</span><span style="color: #333333; font-family: "Segoe UI",sans-serif;">"<o:p></o:p></span></div>
<div class="MsoBodyText">
<br /></div>
<div class="MsoBodyText">
<span style="color: #333333; font-family: "Segoe UI",sans-serif;"><b>Solution:<o:p></o:p></b></span></div>
<div class="MsoBodyText">
<span style="color: #333333; font-family: "Segoe UI",sans-serif;">First we checked if <b>SQL Server Browser</b>
service was running (Log On As) under “Local Service”. We made the changes and
tried to connect SSAS through SQL Server Management Studio (<b>SSMS</b>) but no luck.<o:p></o:p></span></div>
<div class="MsoBodyText">
<span style="color: #333333; font-family: "Segoe UI",sans-serif;"><br /></span></div>
<div class="MsoBodyText">
<span style="color: #333333; font-family: "Segoe UI",sans-serif;">Then we guessed that may be our <b>Windows Firewall</b> was denying
the access. To solve this issue, we added a new inbound rule in Windows
Firewall for <b>TCP port 2383</b>. Please
note that SSAS port is 2383 (instead of SQL port 1433). After adding new port,
we were able to connect SSAS successfully from remote server.<o:p></o:p></span></div>
<div class="MsoBodyText">
<br /></div>
<br />
<div class="MsoBodyText">
<span style="color: #333333; font-family: "Segoe UI",sans-serif;">I
hope this will help you in case you encounter similar problem.<o:p></o:p></span></div>
</div>
SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-16882646198730775642014-03-05T19:00:00.000-08:002014-03-06T11:46:00.584-08:00T-SQL code to parse Numbers from a String<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">Someone asked me recently about <b style="mso-bidi-font-weight: normal;">T-SQL function </b>to parse <b style="mso-bidi-font-weight: normal;">numbers</b> from a <b style="mso-bidi-font-weight: normal;">string</b>. Since there is no built-in function as such, I explained him the logic to calculate same thing using T-SQL code. I will explain the logic here, in case you need to implement same thing (or somewhat similar thing) in your project.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">Let’s take example to understand the problem.<o:p></o:p></span></span></div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableLightGridAccent3" style="border-collapse: collapse; border: currentColor; mso-border-alt: solid #9BBB59 1.0pt; mso-border-themecolor: accent3; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: -1;"> <td style="background-color: transparent; border-color: rgb(155, 187, 89); border-style: solid; border-width: 1pt 1pt 2.25pt; mso-border-bottom-themecolor: accent3; mso-border-themecolor: accent3; padding: 0in 5.4pt; width: 255.4pt;" valign="top" width="341"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 5;">
<b><span style="font-family: "Cambria","serif"; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">Input<o:p></o:p></span></b></div>
</td> <td style="background-color: transparent; border-color: rgb(155, 187, 89) rgb(155, 187, 89) rgb(155, 187, 89) rgb(0, 0, 0); border-style: solid solid solid none; border-width: 1pt 1pt 2.25pt 0px; mso-border-bottom-themecolor: accent3; mso-border-left-alt: solid #9BBB59 1.0pt; mso-border-left-themecolor: accent3; mso-border-right-themecolor: accent3; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 1.75in;" valign="top" width="168"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 1;">
<b><span style="font-family: "Cambria","serif"; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">Output<o:p></o:p></span></b></div>
</td> </tr>
<tr style="mso-yfti-irow: 0;"> <td style="background: rgb(230, 238, 213); border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89); border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: accent3; mso-background-themetint: 63; mso-border-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 255.4pt;" valign="top" width="341"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 68;">
<span style="font-family: "Cambria","serif"; font-size: 12pt; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">Hari12 Sharma34<o:p></o:p></span></div>
</td> <td style="background: rgb(230, 238, 213); border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89) rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: accent3; mso-background-themetint: 63; mso-border-bottom-themecolor: accent3; mso-border-left-alt: solid #9BBB59 1.0pt; mso-border-left-themecolor: accent3; mso-border-right-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 1.75in;" valign="top" width="168"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 64;">
<span style="font-size: 12pt; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">1234<o:p></o:p></span></span></div>
</td> </tr>
<tr style="mso-yfti-irow: 1;"> <td style="background-color: transparent; border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89); border-style: none solid solid; border-width: 0px 1pt 1pt; mso-border-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 255.4pt;" valign="top" width="341"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 132;">
<span style="font-family: "Cambria","serif"; font-size: 12pt; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">My 1st code is D$34A and 2nd code is E#078!!!<o:p></o:p></span></div>
</td> <td style="background-color: transparent; border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89) rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-border-bottom-themecolor: accent3; mso-border-left-alt: solid #9BBB59 1.0pt; mso-border-left-themecolor: accent3; mso-border-right-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 1.75in;" valign="top" width="168"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 128;">
<span style="font-family: "Cambria","serif"; font-size: 12pt; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">1342078<o:p></o:p></span></div>
</td> </tr>
<tr style="mso-yfti-irow: 2;"> <td style="background: rgb(230, 238, 213); border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89); border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: accent3; mso-background-themetint: 63; mso-border-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 255.4pt;" valign="top" width="341"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 68;">
<span style="font-family: "Cambria","serif"; font-size: 12pt; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">Hari# Sharma<o:p></o:p></span></div>
</td> <td style="background: rgb(230, 238, 213); border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89) rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: accent3; mso-background-themetint: 63; mso-border-bottom-themecolor: accent3; mso-border-left-alt: solid #9BBB59 1.0pt; mso-border-left-themecolor: accent3; mso-border-right-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 1.75in;" valign="top" width="168"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 64;">
<span style="font-size: 12pt; mso-bidi-font-size: 11.0pt;"><o:p><span style="font-family: Calibri;"> </span></o:p></span></div>
</td> </tr>
<tr style="mso-yfti-irow: 3; mso-yfti-lastrow: yes;"> <td style="background-color: transparent; border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89); border-style: none solid solid; border-width: 0px 1pt 1pt; mso-border-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 255.4pt;" valign="top" width="341"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 132;">
<span style="font-family: "Cambria","serif"; font-size: 12pt; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">$1#0?0 !?@1<o:p></o:p></span></div>
</td> <td style="background-color: transparent; border-color: rgb(0, 0, 0) rgb(155, 187, 89) rgb(155, 187, 89) rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-border-bottom-themecolor: accent3; mso-border-left-alt: solid #9BBB59 1.0pt; mso-border-left-themecolor: accent3; mso-border-right-themecolor: accent3; mso-border-top-alt: solid #9BBB59 1.0pt; mso-border-top-themecolor: accent3; padding: 0in 5.4pt; width: 1.75in;" valign="top" width="168"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-yfti-cnfc: 128;">
<span style="font-family: "Cambria","serif"; font-size: 12pt; mso-ascii-theme-font: major-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-font-weight: bold; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-fareast-theme-font: major-fareast; mso-hansi-theme-font: major-latin;">1001<o:p></o:p></span></div>
</td> </tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">Here is the code to get the desired output:<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">DECLARE</span><span style="font-family: Consolas;"> <span style="color: teal;">@Str</span> <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span>100<span style="color: grey;">)</span> <span style="color: grey;">=</span> <span style="color: red;">'My 1st code is D$34A and 2nd code is E#078!!!'</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">DECLARE</span><span style="font-family: Consolas;"> <span style="color: teal;">@Position</span> <span style="color: blue;">SMALLINT</span> <span style="color: grey;">=</span> 0</span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">SET</span><span style="font-family: Consolas;"> <span style="color: teal;">@Position</span> <span style="color: grey;">=</span> <span style="color: magenta;">PATINDEX</span><span style="color: grey;">(</span><span style="color: red;">'%[^0-9]%'</span><span style="color: grey;">,</span> <span style="color: teal;">@Str</span><span style="color: grey;">)</span> <span style="color: green;">--Find first character</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
</div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">WHILE </span><span style="color: grey; font-family: Consolas;">(</span><span style="color: teal; font-family: Consolas;">@Position</span><span style="font-family: Consolas;"> <span style="color: grey;">></span> 0<span style="color: grey;">)</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">BEGIN</span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">-- Replace alphabet with empty string.</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">SET</span> <span style="color: teal;">@Str</span> <span style="color: grey;">=</span> <span style="color: magenta;">STUFF</span><span style="color: grey;">(</span><span style="color: teal;">@Str</span><span style="color: grey;">,</span> <span style="color: teal;">@Position</span><span style="color: grey;">,</span> 1<span style="color: grey;">,</span> <span style="color: red;">''</span><span style="color: grey;">)</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">-- Find next alphabet</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">SET</span> <span style="color: teal;">@Position</span> <span style="color: grey;">=</span> <span style="color: magenta;">PATINDEX</span><span style="color: grey;">(</span><span style="color: red;">'%[^0-9]%'</span><span style="color: grey;">,</span> <span style="color: teal;">@Str</span><span style="color: grey;">)</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">END</span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">SELECT</span><span style="font-family: Consolas;"> <span style="color: teal;">@Str</span> <span style="color: teal;">Result</span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><o:p><span style="font-family: Calibri;"> </span></o:p></span></div>
<br />
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas; mso-bidi-font-size: 9.0pt;">Result</span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas; mso-bidi-font-size: 9.0pt;">-------------------------------------</span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas; mso-bidi-font-size: 9.0pt;">1342078<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9pt;"><o:p> </o:p></span></div>
<span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">We can also write function to encapsulate this code and use wherever required.<o:p></o:p></span></span><br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri;"></span><br />
<span style="font-family: Calibri;">This above code can be <strong>optimized </strong>by using <a href="http://sql-question.blogspot.com/2012/10/what-is-tally-table-in-sql-server.html" target="_blank"><strong>Tally</strong></a> table mentioned below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">DECLARE</span><span style="font-family: Consolas;"> <span style="color: teal;">@Str</span> <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span>100<span style="color: grey;">)</span> <span style="color: grey;">=</span> <span style="color: red;">'My 1st code is D$34A and 2nd code is E#078!!!'</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><o:p></o:p></span> </div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">DECLARE</span><span style="font-family: Consolas;"> <span style="color: teal;">@Result</span> <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span>100<span style="color: grey;">)</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">SELECT</span><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: teal;">@Result</span> <span style="color: grey;">=</span> <span style="color: magenta;">COALESCE</span><span style="color: grey;">(</span><span style="color: teal;">@Result</span><span style="color: grey;">,</span> <span style="color: red;">''</span><span style="color: grey;">)</span> <span style="color: grey;">+</span> <span style="color: teal;">Digit</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">FROM<span style="mso-spacerun: yes;"> </span></span><span style="color: grey; font-family: Consolas;">(</span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">SELECT</span><span style="mso-spacerun: yes;"> </span><span style="color: magenta;">SUBSTRING</span><span style="color: grey;">(</span><span style="color: teal;">@Str</span><span style="color: grey;">,</span> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span><span style="color: grey;">,</span> 1<span style="color: grey;">)</span> <span style="color: blue;">AS</span> <span style="color: teal;">Digit</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">FROM</span><span style="mso-spacerun: yes;"> </span><span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">Tally</span> <span style="color: teal;">t</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">WHERE</span><span style="mso-spacerun: yes;"> </span><span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;"><=</span> <span style="color: magenta;">LEN</span><span style="color: grey;">(</span><span style="color: teal;">@Str</span><span style="color: grey;">)</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">AND</span><span style="mso-spacerun: yes;"> </span><span style="color: magenta;">PATINDEX</span><span style="color: grey;">(</span><span style="color: red;">'%[0-9]%'</span><span style="color: grey;">,</span> <span style="color: magenta;">SUBString</span><span style="color: grey;">(</span><span style="color: teal;">@Str</span><span style="color: grey;">,</span> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span><span style="color: grey;">,</span> 1<span style="color: grey;">))</span> <span style="color: grey;">=</span> 1</span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">)</span> <span style="color: teal;">stg</span></span></div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas;"><o:p></o:p></span> </div>
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas;">SELECT</span><span style="font-family: Consolas;"> <span style="color: teal;">@Result</span> <span style="color: teal;">Result<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<o:p><span style="font-family: Calibri;"><br />
<br />
</span></o:p><br />
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Calibri;"><span style="font-family: Consolas; mso-bidi-font-size: 9.0pt;">Result</span></span></div>
<span style="font-family: Calibri;">
</span><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Calibri;"><span style="font-family: Consolas; mso-bidi-font-size: 9.0pt;">-------------------------------------</span></span></div>
<span style="font-family: Calibri;">
<div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;">
<span style="font-family: Consolas; mso-bidi-font-size: 9.0pt;">1342078<o:p></o:p></span></div>
</span><br /></div>
SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-59634463969861351222014-01-14T09:00:00.000-08:002014-01-14T19:42:21.898-08:00SSIS 2012 - Package Configurations<div class="MsoNormal">
When I started working on SSIS 2012 using SQL Server Data Tools (<b>SSDT</b>), I noticed that SSIS package configuration option was missing. It was available in previous version of SSIS under Control Flow. We could see package configuration by right click on Control Flow surface area. Unfortunately, that option is missing now.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So I am writing this blog to provide help in case you are running into the same issue. I will explain <b>SSIS 2012 Package Configuration</b> in case you are wondering how to implement Package Configuration in SSIS 2012. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>PROBLEM</b>: Package Configuration option is missing as shown in below screenshot:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaEQ2R_qfO_EV7QBk5cDf6l0MEOi7odFASs-Xui4xdUm_yZ-p4tlDOw3xiECjykbezbrBMD1bqro_gbSuAjUF6DS3wAoBvEJeITwpY6N2alkO6BTMiwPdsFp4pcqvd6yOFqYu71rrSR_8/s1600/Capture1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaEQ2R_qfO_EV7QBk5cDf6l0MEOi7odFASs-Xui4xdUm_yZ-p4tlDOw3xiECjykbezbrBMD1bqro_gbSuAjUF6DS3wAoBvEJeITwpY6N2alkO6BTMiwPdsFp4pcqvd6yOFqYu71rrSR_8/s1600/Capture1.PNG" height="579" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal">
Here is what MSDN describes: <u><span style="color: #0070c0;"><a href="http://msdn.microsoft.com/en-us/library/ms141132(v=sql.110).aspx" target="_blank"><u><span style="color: #0070c0;">Create Package Configuration</span></u></a></span></u>. Unfortunately, I could not find “Package Configuration” option there as well. However, I got a hint from the Notes on the same MSDN link which says:<br />
<o:p></o:p> </div>
<div class="MsoNormal" style="text-align: justify;">
<i><span style="background: rgb(217, 217, 217); mso-shading-themecolor: background1; mso-shading-themeshade: 217;">You can also access the <b>Package Configuration Organizer</b>, by clicking the ellipsis button next to the <b>Configuration</b> property. The <b>Configuration</b> property appears in the properties window for the package.</span><o:p></o:p></i></div>
<br />
<div class="MsoNormal">
<br /></div>
<h3>
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Follow these steps to create a package configuration:<o:p></o:p></span></h3>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">1.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">In SQL Server Data Tools (<b>SSDT</b>), open the Integration Services project.<o:p></o:p></span></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">2.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">In Solution Explorer, double-click the package to open it.<o:p></o:p></span></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">3.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">To open <b>Package Configuration Organizer</b>, click on the <span class="label">ellipse button next to the <span style="background: rgb(79, 145, 251); color: white; mso-themecolor: background1;">Configurations</span> property.</span><o:p></o:p></span></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span class="label"><br />
</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghQAOpmbmISvcOWEI_JYzxT_osULyoPC9GCZMz8aBcBeqx9gjyMZZQIbofkriAF-3r4jAKN6MvlD8czxptXKr59Hv7WNgZREVDqljtZWt1k1LcrN3fRRy_ZB8dfS8zfj4vfV6Y1PHWcg/s1600/Capture2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghQAOpmbmISvcOWEI_JYzxT_osULyoPC9GCZMz8aBcBeqx9gjyMZZQIbofkriAF-3r4jAKN6MvlD8czxptXKr59Hv7WNgZREVDqljtZWt1k1LcrN3fRRy_ZB8dfS8zfj4vfV6Y1PHWcg/s1600/Capture2.png" height="400" width="357" /></a></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span class="label"><br />
</span></span></div>
<div align="left" style="margin-left: 0.5in;">
<!--[if gte vml 1]><v:shapetype id="_x0000_t75"
coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="Picture_x0020_6" o:spid="_x0000_i1031" type="#_x0000_t75"
style='width:273.75pt;height:305.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\v-hanash\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/> </v:shape><![endif]--><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span><br /></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">4.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">In the <span class="label">Package Configuration Organizer</span> dialog box, select <span class="label"><b>Enable</b> <b>package configurations</b></span>, and then click <span class="label"><b>Add</b> button.</span><o:p></o:p></span></div>
<div align="left" style="margin-left: 0.5in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyOhb2wyDOJOiMcOWjEL5NcaPhdabnsih6Ttd9lwCPhBObfoGQWhVils1Gf8oUBGWylMUg61tgC7G0MPJ_gR8I4LqRV_FSP9PheNPE-wiU_3GDUwvbfnMPBmSaBRmHdNnEuVnWDCUQcKI/s1600/Capture3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyOhb2wyDOJOiMcOWjEL5NcaPhdabnsih6Ttd9lwCPhBObfoGQWhVils1Gf8oUBGWylMUg61tgC7G0MPJ_gR8I4LqRV_FSP9PheNPE-wiU_3GDUwvbfnMPBmSaBRmHdNnEuVnWDCUQcKI/s1600/Capture3.png" height="301" width="400" /></a></div>
<span lang="EN"><o:p></o:p></span><br />
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">5.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">On the welcome page of the <b>Package Configuration Wizard</b> page, click <span class="label"><b>Next</b> button</span>. <o:p></o:p></span></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">6.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">On the <b>Select Configuration Type</b> page, specify the configuration type, and then set the properties that are relevant to the configuration type.<o:p></o:p></span></div>
<div align="left" style="margin-left: 0.5in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">I am using “XML configuration file” in <b>Configuration type</b>. Now specify configuration file path in configuration. Click <b>Next</b> button.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3ftgxsWhyphenhyphenHxSXM9ZDHsU0abN3lFqxY7zlswFofxnU7Vufh3E-OCoEGMSDP9XgAqH6tJD65Kpf98ryL8YbCtGh1u1JzPREOzAYFlkx_XPJiArfXiyugVTujVCN6tu6S47wQm_A5rd4VCQ/s1600/Capture4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3ftgxsWhyphenhyphenHxSXM9ZDHsU0abN3lFqxY7zlswFofxnU7Vufh3E-OCoEGMSDP9XgAqH6tJD65Kpf98ryL8YbCtGh1u1JzPREOzAYFlkx_XPJiArfXiyugVTujVCN6tu6S47wQm_A5rd4VCQ/s1600/Capture4.png" height="361" width="400" /></a></div>
<div align="left" style="margin-left: 0.5in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br />
</span></div>
<div align="left" style="margin-left: 0.5in;">
<!--[if gte vml 1]><v:shape id="Picture_x0020_8"
o:spid="_x0000_i1029" type="#_x0000_t75" style='width:375.75pt;height:340.5pt;
visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\v-hanash\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png"
o:title=""/> </v:shape><![endif]--><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span><br /></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">7.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">On the <b>Select Properties to Export</b> page, select the properties of package objects to include in the configuration. If the configuration type supports only one property, the title of this wizard page is <b>Select Target Property</b>. <o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGpasWW6d4myzWTa25eRTkWUO-aGg_tnfhSwfPJCSi95Fh1ex-taKLd2TJMJyt5iSCLdMLflzxm203BNBNvA5OR6d6S6ML0nAkf5vUgQevm8QM1Rk1qhJPWrj0laDB5IIdSdMPg-8XFLA/s1600/Capture5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGpasWW6d4myzWTa25eRTkWUO-aGg_tnfhSwfPJCSi95Fh1ex-taKLd2TJMJyt5iSCLdMLflzxm203BNBNvA5OR6d6S6ML0nAkf5vUgQevm8QM1Rk1qhJPWrj0laDB5IIdSdMPg-8XFLA/s1600/Capture5.png" height="400" width="360" /></a></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br />
</span></div>
<div align="left">
<!--[if gte vml 1]><v:shape id="Picture_x0020_9"
o:spid="_x0000_i1028" type="#_x0000_t75" style='width:375.75pt;height:417pt;
visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\v-hanash\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png"
o:title=""/> </v:shape><![endif]--><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span><br /></div>
<table border="0" cellpadding="0" class="MsoNormalTable" style="margin-left: 0.5in; mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184;"><tbody>
<tr> <td style="padding: 0.75pt;"><div class="MsoNormal">
<b><!--[if gte vml 1]><v:shape id="Picture_x0020_4"
o:spid="_x0000_i1027" type="#_x0000_t75" alt="Note" style='width:.75pt;
height:.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\v-hanash\AppData\Local\Temp\msohtmlclip1\01\clip_image006.gif"
o:title="Note"/> </v:shape><![endif]--><img alt="Note" height="1" src="file:///C:/Users/v-hanash/AppData/Local/Temp/msohtmlclip1/01/clip_image006.gif" v:shapes="Picture_x0020_4" width="1" /><strong><span style="font-family: "Calibri","sans-serif"; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Note</span></strong> </b><b><span style="font-size: 12pt; line-height: 115%;"><o:p></o:p></span></b></div>
</td> </tr>
<tr> <td style="padding: 0.75pt;"><span style="font-family: "Calibri","sans-serif"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><i>Only the <span class="label">XML Configuration File</span> and <span class="label">SQL Server</span> configuration types support including multiple properties in a configuration</i>.<o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br />
</span> </td> </tr>
</tbody></table>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">8.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">On the Completing the Wizard page, type the name of the configuration, and then click <span class="label"><b>Finish</b></span>.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOU4Ki8CqfvBe7Jh4r-onQunly7p0VzGnuULlbJqdckaYBHymjT11U248a4QCRIliQtBEiuzeuzTH9nGeUlu4jug-WdrGJMkC4h7zUm8SsdNHtrYcv-G4JSjt1ENTJ2icxIYpW7Gs71lY/s1600/Capture6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOU4Ki8CqfvBe7Jh4r-onQunly7p0VzGnuULlbJqdckaYBHymjT11U248a4QCRIliQtBEiuzeuzTH9nGeUlu4jug-WdrGJMkC4h7zUm8SsdNHtrYcv-G4JSjt1ENTJ2icxIYpW7Gs71lY/s1600/Capture6.png" height="400" width="360" /></a></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br />
</span></div>
<div align="left" style="margin-left: 0.5in;">
<!--[if gte vml 1]><v:shape id="Picture_x0020_10"
o:spid="_x0000_i1026" type="#_x0000_t75" style='width:375.75pt;height:417pt;
visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\v-hanash\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png"
o:title=""/> </v:shape><![endif]--><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span><br /></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">9.<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">View the configuration in the <span class="label">Package Configuration Organizer</span> dialog box and click <b>Close</b> button.<o:p></o:p></span></div>
<div align="left" style="margin-left: 0.5in;">
<!--[if gte vml 1]><v:shape id="Picture_x0020_11"
o:spid="_x0000_i1025" type="#_x0000_t75" style='width:468pt;height:352.5pt;
visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\v-hanash\AppData\Local\Temp\msohtmlclip1\01\clip_image008.png"
o:title=""/> </v:shape><![endif]--><span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span><br /></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj35gJRc9cnEvQc3VXufc9zrnbdAVMhXqsKylr0YfPE4bkg5UQV7JKxQZSHQDWQ9fUf2-Oj-riqJABrWCzpYkeGrZ-VajDcyJnEDhScx6oXeIXx7RJlyhqCvMrit1MWWqsOmyaDgWm0200/s1600/Capture7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj35gJRc9cnEvQc3VXufc9zrnbdAVMhXqsKylr0YfPE4bkg5UQV7JKxQZSHQDWQ9fUf2-Oj-riqJABrWCzpYkeGrZ-VajDcyJnEDhScx6oXeIXx7RJlyhqCvMrit1MWWqsOmyaDgWm0200/s1600/Capture7.png" height="301" width="400" /></a></div>
<br />
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span class="label"><span style="font-size: 11pt; line-height: 115%;"><br />
</span></span></span></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span class="label"><span style="font-size: 11pt; line-height: 115%;"><br />
</span></span></span></div>
<div align="left" style="margin-left: 0.5in; text-indent: -0.25in;">
<span lang="EN" style="font-family: "Calibri","sans-serif"; mso-ansi-language: EN; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span class="label"> <span style="font-size: 11pt; line-height: 115%;">I hope this post is helpful!</span></span></span></div>
SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-68158836932194987862013-02-10T09:00:00.000-08:002013-07-21T22:55:40.124-07:00Date-Range multiple tables using T-SQLDid you ever come across a situation where you need to join multiple tables (consisting FromDate and ToDate) and combine the data into single target table with proper date range?<br />
<br />
In this blog post, I will try to explain how to date-range two source tables into single table based on FromDate and ToDate.<br />
<br />
<strong>Problem</strong>: There are two tables <strong>Address</strong> and <strong>Email</strong>. Address of any customer can change at any point of time. Likewise, Email ID of customer can be changed at time. We need to track this information using FromDate (start time) and ToDate (end time). <br />
<br />
Below are the sample data of these tables:<br />
<br />
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; width: 491px;">
<colgroup><col style="mso-width-alt: 2889; mso-width-source: userset; width: 59pt;" width="79"></col>
<col style="mso-width-alt: 3145; mso-width-source: userset; width: 65pt;" width="86"></col>
<col style="mso-width-alt: 5376; mso-width-source: userset; width: 110pt;" width="147"></col>
<col style="mso-width-alt: 3291; mso-width-source: userset; width: 68pt;" width="90"></col>
<col style="mso-width-alt: 3254; mso-width-source: userset; width: 67pt;" width="89"></col>
<tbody>
<tr height="20" style="height: 15pt;">
<td class="xl66" height="20" style="background-color: #1f497d; border-color: windowtext windowtext white; border-style: solid solid none; border-width: 0.5pt 0.5pt 0px; height: 15pt; width: 59pt;" width="79"><strong><span style="color: white; font-family: Calibri;">Address</span></strong></td>
<td style="background-color: transparent; border: 0px black; width: 65pt;" width="86"></td>
<td style="background-color: transparent; border: 0px black; width: 110pt;" width="147"></td>
<td style="background-color: transparent; border: 0px black; width: 68pt;" width="90"></td>
<td style="background-color: transparent; border: 0px black; width: 67pt;" width="89"></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl68" height="20" style="background-color: #b8cce4; border: 0.5pt solid windowtext; height: 15pt;"><span style="font-family: Calibri;">AddressID</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">CustomerID</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">FullAddress</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">FromDate</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">ToDate</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">148th Ave NE, A10</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2005-07-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2006-08-07</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">2</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">156th Ave NE, D5</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2006-08-08</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2009-11-20</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">3</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1100 NE 40th ST, A10</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2009-11-21</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2011-03-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">4</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">148th Ave NE, J101</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2011-04-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">9999-12-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">5</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">14528 NE 40th ST</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2007-05-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2008-04-15</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">6</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">140th Ave NE, K11</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2008-04-16</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2012-06-25</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">7</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">145th Ave NE 31st ST</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2012-06-26</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">9999-12-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td height="20" style="background-color: transparent; border: 0px black; height: 15pt;"></td>
<td style="background-color: transparent; border: 0px black;"></td>
<td style="background-color: transparent; border: 0px black;"></td>
<td style="background-color: transparent; border: 0px black;"></td>
<td style="background-color: transparent; border: 0px black;"></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl66" height="20" style="background-color: #1f497d; border-color: windowtext windowtext white; border-style: solid solid none; border-width: 0.5pt 0.5pt 0px; height: 15pt;"><strong><span style="color: white; font-family: Calibri;">Email</span></strong></td>
<td style="background-color: transparent; border: 0px black;"></td>
<td style="background-color: transparent; border: 0px black;"></td>
<td style="background-color: transparent; border: 0px black;"></td>
<td style="background-color: transparent; border: 0px black;"></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl68" height="20" style="background-color: #b8cce4; border: 0.5pt solid windowtext; height: 15pt;"><span style="font-family: Calibri;">EmailID</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">CustomerID</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">EmailAddress</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">FromDate</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">ToDate</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari11@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2005-07-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2010-09-30</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">2</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari21@yahoo.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2010-10-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2012-12-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">3</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari31@hotmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2013-01-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">9999-12-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">4</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">john42@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2007-05-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2013-03-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">5</span></td>
<td class="xl69" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">john52@hotmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2013-04-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">9999-12-31</span></td>
</tr>
</tbody></colgroup></table>
<br />
Now consider the above scenario and data, we need following output from these two tables:<br />
<br />
<strong><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; width: 559px;">
<colgroup><col style="mso-width-alt: 3145; mso-width-source: userset; width: 65pt;" width="86"></col>
<col span="2" style="mso-width-alt: 5376; mso-width-source: userset; width: 110pt;" width="147"></col>
<col style="mso-width-alt: 3291; mso-width-source: userset; width: 68pt;" width="90"></col>
<col style="mso-width-alt: 3254; mso-width-source: userset; width: 67pt;" width="89"></col>
<tbody>
<tr height="20" style="height: 15pt;">
<td class="xl66" height="20" style="background-color: #1f497d; border-color: windowtext windowtext white; border-style: solid solid none; border-width: 0.5pt 0.5pt 0px; height: 15pt; width: 65pt;" width="86"><strong><span style="color: white; font-family: Calibri;">Output</span></strong></td>
<td style="background-color: transparent; border: 0px black; width: 110pt;" width="147"></td>
<td style="background-color: transparent; border: 0px black; width: 110pt;" width="147"></td>
<td style="background-color: transparent; border: 0px black; width: 68pt;" width="90"></td>
<td style="background-color: transparent; border: 0px black; width: 67pt;" width="89"></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl68" height="20" style="background-color: #b8cce4; border: 0.5pt solid windowtext; height: 15pt;"><span style="font-family: Calibri;">CustomerID</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">FullAddress</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">EmailAddress</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">FromDate</span></td>
<td class="xl68" style="background-color: #b8cce4; border-color: windowtext windowtext windowtext black; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">ToDate</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">148th Ave NE, A10</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari11@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2005-07-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2006-08-07</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">156th Ave NE, D5</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari11@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2006-08-08</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2009-11-20</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1100 NE 40th ST, A10</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari11@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2009-11-21</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2010-09-30</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">1100 NE 40th ST, A10</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari21@yahoo.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2010-10-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2011-03-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">148th Ave NE, J101</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari21@yahoo.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2011-04-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2012-12-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">1</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">148th Ave NE, J101</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">hari31@hotmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2013-01-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">9999-12-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">14528 NE 40th ST</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">john42@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2007-05-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2008-04-15</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">140th Ave NE, K11</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">john42@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2008-04-16</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2012-06-25</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">145th Ave NE 31st ST</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">john42@gmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2012-06-26</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2013-03-31</span></td>
</tr>
<tr height="20" style="height: 15pt;">
<td class="xl69" height="20" style="background-color: transparent; border-color: black windowtext windowtext; border-style: none solid solid; border-width: 0px 0.5pt 0.5pt; height: 15pt;"><span style="font-family: Calibri;">2</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">145th Ave NE 31st ST</span></td>
<td class="xl65" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">john52@hotmail.com</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">2013-04-01</span></td>
<td class="xl67" style="background-color: transparent; border-color: black windowtext windowtext black; border-style: none solid solid none; border-width: 0px 0.5pt 0.5pt 0px;"><span style="font-family: Calibri;">9999-12-31</span></td>
</tr>
</tbody></colgroup></table>
</strong><strong></strong><br />
<strong>Solution</strong>: There could be several ways to achieve the above output. Here is one the T-SQL scripts to get the desired output:<br />
<span style="color: green; font-family: Consolas;"><span style="color: green; font-family: Consolas;"><span style="color: green; font-family: Consolas;">----------------------------------------------------------<br />
--Description: Script to combine different date-ranged<br />
-- columns into single date-ranged table.
<br />
----------------------------------------------------------<br />
</span> </span> </span><span style="font-family: Consolas;"><span style="font-family: Consolas;">
</span></span><br />
<span style="color: green; font-family: Consolas;">
<span style="color: green; font-family: Consolas;">
<span style="color: green; font-family: Consolas;">
----------------------------------------------------------<br />
--Create test tables<br />
----------------------------------------------------------<br />
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">IF</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">OBJECT_ID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'tempdb..#Address'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'U'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">IS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DROP</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">TABLE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Address</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">CREATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">TABLE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Address</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
(<br />
</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"> AddressID</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">IDENTITY</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FullAddress</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VARCHAR</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">100</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">CONSTRAINT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">PKC_Address</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">PRIMARY</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">KEY</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">CLUSTERED</span></span></span><br />
<span style="color: blue; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
<br />
)<br />
</span> </span> </span><span style="font-family: Consolas;"><span style="font-family: Consolas;">
</span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">IF</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">OBJECT_ID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'tempdb..#Email'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'U'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">IS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DROP</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">TABLE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Email</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">CREATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">TABLE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Email</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><br />
(<br />
</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"> EmailID</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">IDENTITY</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmailAddress</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VARCHAR</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">50</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">CONSTRAINT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">PKC_Email</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">PRIMARY</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">KEY</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">CLUSTERED</span></span></span><br />
<span style="color: blue; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
<br />
)<br />
</span> </span> </span><span style="font-family: Consolas;"><span style="font-family: Consolas;">
</span></span><br />
<span style="color: green; font-family: Consolas;">
<span style="color: green; font-family: Consolas;">
<span style="color: green; font-family: Consolas;">
----------------------------------------------------------<br />
--Insert test data<br />
----------------------------------------------------------<br />
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INSERT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Address</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FullAddress</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VALUES</span></span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> (</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'148th Ave NE, A10'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2005-07-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2006-08-07'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'156th Ave NE, D5'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2006-08-08'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2009-11-20'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'1100 NE 40th ST, A10'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2009-11-21'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2011-03-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'148th Ave NE, J101'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2011-04-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'9999-12-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'14528 NE 40th ST'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2007-05-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2008-04-15'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'140th Ave NE, K11'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2008-04-16'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2012-06-25'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'145th Ave NE 31st ST'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2012-06-26'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'9999-12-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><br />
<span style="font-family: Consolas;">
<span style="font-family: Consolas;">
<br />
</span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INSERT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Email</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmailAddress</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VALUES</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: blue; font-family: Consolas;"> </span>(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'hari11@gmail.com'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2005-07-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2010-09-30'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'hari21@yahoo.com'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2010-10-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2012-12-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'hari31@hotmail.com'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2013-01-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'9999-12-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'john42@gmail.com'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2007-05-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2013-03-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'john52@hotmail.com'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'2013-04-01'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'9999-12-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">
</span></span><br />
<span style="color: green; font-family: Consolas;">
<span style="color: green; font-family: Consolas;">
<span style="color: green; font-family: Consolas;">
----------------------------------------------------------<br />
--Verify test data<br />
----------------------------------------------------------<br />
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">*</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FROM</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Address</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">*</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FROM</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Email</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">
</span></span><br />
<span style="color: green; font-family: Consolas;"><br />
<span style="color: green; font-family: Consolas;">
<span style="color: green; font-family: Consolas;">
----------------------------------------------------------<br />
--T-SQL code to get the required output<br />
----------------------------------------------------------<br />
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT </span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FullAddress</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmailAddress</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: blue; font-family: Consolas;">
<span style="color: blue; font-family: Consolas;">
<span style="color: blue; font-family: Consolas;">
FROM<br />
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(<br />
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT </span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">a</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">a</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FullAddress</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">e</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmailAddress</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,(</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">MAX</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">U</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><br />
<span style="font-family: Consolas;"><span style="color: blue;"><span style="color: blue;"><span style="color: blue;"><span style="color: black;"> </span>FROM </span></span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VALUES </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">a</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">),</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">e</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">))</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">U</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> )</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> ,(</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">MIN</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">U</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><br />
<span style="font-family: Consolas;"><span style="color: blue;"><span style="color: blue;"><span style="color: blue;"><span style="color: black;"> </span>FROM </span></span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VALUES </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">a</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">),</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">e</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">))</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">U</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"> )</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FROM</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Address</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">a</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">LEFT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">JOIN </span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">#Email</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">e</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">ON</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">a</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">=</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">e</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">CustomerID</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">WHERE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">ISNULL</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">FromDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'9999-12-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><=</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">ISNULL</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">t1</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ToDate</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'9999-12-31'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="color: blue; font-family: Consolas;">
<span style="color: blue; font-family: Consolas;">
<span style="color: blue; font-family: Consolas;"><br />
GO</span></span></span><br />
<span style="color: blue; font-family: Consolas;"></span><br />
SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-82140499288214796362013-01-05T10:00:00.000-08:002013-03-24T13:25:08.975-07:00
<span style="font-family: "Calibri","sans-serif"; font-size: x-large; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><strong>OFFSET
AND FETCH</strong></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span style="font-family: Times New Roman;">
</span><strong><span style="font-size: 16pt; line-height: 115%;">S</span>QL Server
2012</strong> introduces brand new query hints that allow you to implement query paging
solution. In the past, we have used <strong>TOP</strong> operator to return the top # number of
rows from a table. However, OFFSET & FETCH query clauses can give you more
benefits than just the TOP operator.<o:p></o:p><br />
<span style="font-family: Times New Roman;">
</span><br />
</span><br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><b>OFFSET:</b> Allows you to offset the record pointer to a
specific row in a table</span><span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><br />
</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><b>FETCH:</b> Allows you to fetch/return number of rows you
request in Fetch.<o:p></o:p></span></div>
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">
<span style="font-family: Times New Roman;">
</span>
</span><br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">OFFSET and FETCH when used together can return the
exact/precise set of data you are looking for.</span></div>
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">
</span><br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Let's take few examples to understand these features.</span></div>
<br />
<span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">I am creating Employee as base table to use in my examples.<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
</div>
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">IF</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">OBJECT_ID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'dbo.Employee'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'U'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">IS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DROP</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">TABLE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">dbo</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Employee</span></span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">CREATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">TABLE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">dbo</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Employee</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
(</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeID</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">NVARCHAR</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">100</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">BasicSalary</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">DOB</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DATE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NOT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">NULL</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span><br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INSERT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">dbo</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Employee</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeID</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeName</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">BasicSalary</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">DOB</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: blue; font-family: Consolas;">VALUES</span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">1</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Hari'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 5000</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'1983-05-05'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'John'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 3500</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'1978-10-25'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">3</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Peter'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 4500</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'1982-02-10'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">4</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Ravi'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 2500</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'1980-03-04'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span><br />
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">5</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Max'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 3600</span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'1985-09-20'</span></span></span><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">)</span></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;"><span style="color: grey; font-family: Consolas; font-size: xx-small;">
</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span></div>
<span style="font-family: Times New Roman;">
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeID</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeName</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">BasicSalary</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">
</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">DOB</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;">
</span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FROM</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">dbo</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Employee</span></span></span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZA8f1dm7rCGuFOWSJFEpzKZTzr5VrAKBpBP8KRTbfxkcuI5CzChqfKmSna0tfwFryT707umficzFQvIr4JVoCW44LLxuIN3rpJDWwlLLuTzq_Fgg0iRmbHoUg7hMR0UDzhdSd_Srbk8M/s1600/Capture.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="109" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZA8f1dm7rCGuFOWSJFEpzKZTzr5VrAKBpBP8KRTbfxkcuI5CzChqfKmSna0tfwFryT707umficzFQvIr4JVoCW44LLxuIN3rpJDWwlLLuTzq_Fgg0iRmbHoUg7hMR0UDzhdSd_Srbk8M/s320/Capture.PNG" width="320" /></a></div>
</span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Use <strong>OFFSET</strong> to offset the record pointer to a specific row in a table:<br />
<br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeID</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeName</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">BasicSalary</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">DOB</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FROM</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">dbo</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Employee</span></span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">ORDER</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">BY</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeID</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">OFFSET</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 2 </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">ROWS</span></span></span><br />
<span style="color: blue; font-family: Consolas;"></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9_nTcFdw9YH0kzziVTWiF6qK5qvM23E76-6gtLN-un_5hvSpjVhwMhbkZy2QL1VLLoKFE9fBFoY95a9Bx0cCLpUOUm4-BZVKf2oS2yxP96qnfVznUVpVE-VqXM7fsybV6ej4SunprwT8/s1600/Capture1.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="72" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9_nTcFdw9YH0kzziVTWiF6qK5qvM23E76-6gtLN-un_5hvSpjVhwMhbkZy2QL1VLLoKFE9fBFoY95a9Bx0cCLpUOUm4-BZVKf2oS2yxP96qnfVznUVpVE-VqXM7fsybV6ej4SunprwT8/s320/Capture1.PNG" width="320" /></a></div>
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">
</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span></span><br />
<br />
<br />
<br />
<br />
<br />
Use <strong>OFFSET</strong> to offset the record pointer to a specific row in a table and use <strong>FETCH</strong> to pull only required number of rows:<br />
<br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeID</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeName</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">BasicSalary</span></span></span><br />
<span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">DOB</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FROM</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">dbo</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Employee</span></span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">ORDER</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">BY</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">EmployeeID</span></span></span><br />
<span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">OFFSET</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 2 </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">ROWS</span></span></span><br />
<span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FETCH</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">NEXT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 2 </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">ROWS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ONLY</span></span></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9CMFjXrFu4jlPiURnPzXyCTJaBTJGi6eP-ffFDZL50nARYAyY55gAZlfDGrya6iPF8ewKnsIxHF8L_wWdcA873hxwgpVrnLDezfcPW5xBhgx_kCifmLwN9pzwHiPIXiH2Y3Y0iX8WNls/s1600/Capture2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="60" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9CMFjXrFu4jlPiURnPzXyCTJaBTJGi6eP-ffFDZL50nARYAyY55gAZlfDGrya6iPF8ewKnsIxHF8L_wWdcA873hxwgpVrnLDezfcPW5xBhgx_kCifmLwN9pzwHiPIXiH2Y3Y0iX8WNls/s320/Capture2.PNG" width="320" /></a></div>
<span style="color: teal; font-family: Consolas;"></span><br />
<span style="color: teal; font-family: Consolas; font-size: x-small;"></span>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-29356931599716661442012-11-10T00:00:00.000-08:002013-03-23T13:09:38.922-07:00Dynamic Color Coding in SSRS Charts<div dir="ltr" style="text-align: left;" trbidi="on">In this article, I will explain <strong>how to change the color of a chart dynamically</strong>. In other words, how to provide custom <strong>color palette</strong> feature at run time.<br /><br />Lets start off with an example including step by step operations.<br /><br /><strong>Step1</strong>. Open or create new <strong>Report Server Project</strong>. I am creating a new Report Server Project using SQL Server 2012 and saved it with <strong>LearnSSRS2012</strong> name. <br /><br /><strong>Step2</strong>. Add new <strong>Shared Data Source</strong> by right click on "Shared Data Sources" folder.<br /><br /><div align="left" class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqTa3518_IMI4GbgAF73zqjTcvhVWk_kndZuUZxIPg-sSirFT6L-SsULbgIUy1pREUVXW80oUrBTQoreHxPwMyp3VJHRC8G_RPExUqtw70KQ3O8EnuJsbF3KJwwqpGiXocPcX5v23OxdU9/s1600/DynamicChartCode0.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqTa3518_IMI4GbgAF73zqjTcvhVWk_kndZuUZxIPg-sSirFT6L-SsULbgIUy1pREUVXW80oUrBTQoreHxPwMyp3VJHRC8G_RPExUqtw70KQ3O8EnuJsbF3KJwwqpGiXocPcX5v23OxdU9/s1600/DynamicChartCode0.png" /></a> </div><div class="separator" style="clear: both; text-align: left;"> Now give any name to Share Data Source (Local, in my case) and click on Edit button to define Server Name and Database Name. In this example, I will use static data sources so I am using "." (you can also use "(local)") as ServerName. I am not defining any Database name so I will keep it blank (default will be msater). You can define any database, if you want. Now click on OK.</div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR1_V5lo1I6mJNzd4TI3WMjPJBrJ59DaUBkrdpbOjHnwMv2LWZFq_zJUQFFGgQvdWYcuLeVXY9_I70lK-SLyiZG-K78MxDZfvWD0ltajCaZQOkujd6E4xq9ZYdTCKF24WqUioloSH0a2po/s1600/DynamicChartCode0.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="293" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR1_V5lo1I6mJNzd4TI3WMjPJBrJ59DaUBkrdpbOjHnwMv2LWZFq_zJUQFFGgQvdWYcuLeVXY9_I70lK-SLyiZG-K78MxDZfvWD0ltajCaZQOkujd6E4xq9ZYdTCKF24WqUioloSH0a2po/s400/DynamicChartCode0.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong></strong><br /><strong></strong><br /><strong>Step3</strong>. Now create a new report by clicking on Reports --> Add --> New Item --> Report --> Add. I don't like default report name like Report1, Report2, Report3 so I have renamed it to <strong>ChartColorCode.rdl</strong>.<br /><br /><strong>Step4</strong>. Create Data Source for ChartColorCode report. To create a new Data Source, right click on "Data Sources" followed by "Add Data Sources" under Report Data as shown below:<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6EqOjG0sQ9MOIDd0yEntTtnAGe2bin6tYOa3VvKLePIxjzBnqgm1fElTTDtbpWOMJl_12cJ8SI8rELJC5W8bdZ8pqqvtrhVc_SaXaNYmzzzFP_H84OiI12nDtWo9-g2MqbnhiiAItzn8T/s1600/DynamicChartCode02.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6EqOjG0sQ9MOIDd0yEntTtnAGe2bin6tYOa3VvKLePIxjzBnqgm1fElTTDtbpWOMJl_12cJ8SI8rELJC5W8bdZ8pqqvtrhVc_SaXaNYmzzzFP_H84OiI12nDtWo9-g2MqbnhiiAItzn8T/s1600/DynamicChartCode02.png" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />We will use Shared Data Source we created above. So click on "Use shared data source reference" and select <strong>Local</strong> data source created at step 2. Give any name to this report level data source. I will assign "Local" again. Click OK to proceed.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ_YVJHm0-KX1we73S5ElMHqY4EFsOJa_ygcwQLjfI9dqExa5PPPhSIqs3-fltvynaQAAWL33FrEfgaFhCHR9uhymvvOSe_WFVdfIUL6zK-VkMgpvuN9S_Od-rUzjfmCr-IaRPgWQ4Un-D/s1600/DynamicChartCode03.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="293" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ_YVJHm0-KX1we73S5ElMHqY4EFsOJa_ygcwQLjfI9dqExa5PPPhSIqs3-fltvynaQAAWL33FrEfgaFhCHR9uhymvvOSe_WFVdfIUL6zK-VkMgpvuN9S_Od-rUzjfmCr-IaRPgWQ4Un-D/s400/DynamicChartCode03.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong></strong><br /><strong>Step5</strong>. Now lets create couple of datasets. To create a new dataset, right click on "Datastes" followed by "Add Datastes" under Report Data as shown below:<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmluPYPGEjmH3nZHt9XO5ZmI3dGf9uuXgPkMuzatFWosyZ9sPIsaPlCwnntLfN8n0M5mNJWqXkRuBOECG5FhJzcJSJ3u13HTfVAT0-kEHgHWcHZLB7zkw-XiZ-wtTyz9DaK5riGcjllds8/s1600/DynamicChartCode02.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmluPYPGEjmH3nZHt9XO5ZmI3dGf9uuXgPkMuzatFWosyZ9sPIsaPlCwnntLfN8n0M5mNJWqXkRuBOECG5FhJzcJSJ3u13HTfVAT0-kEHgHWcHZLB7zkw-XiZ-wtTyz9DaK5riGcjllds8/s1600/DynamicChartCode02.png" /><br /> </a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />I will use two data sources in this example, one for <em><strong>Color Palette</strong></em> and another for <em><strong>Chart</strong></em>.<br /><br />To create new Dataset for ColorPalette, Right click on DataSets --> Add Dataset... and type "ColorPalette" in Name textbox. Select "Use a dataset embedded in my report" option and select Local as Data Source.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivvzlTRt9bMq8f8SJT4aKAzQ2DWd89asviNX7xkboaOi7sG_DvijFhlafh20Al7P03osmvKC2drKPmYx2NUT2XcSGCGv9ja-X6ntyhDh7xBROuJGqFXBlC4Q1yuPQGe9VzeHwOJz6Pbghd/s1600/DynamicChartCode04.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivvzlTRt9bMq8f8SJT4aKAzQ2DWd89asviNX7xkboaOi7sG_DvijFhlafh20Al7P03osmvKC2drKPmYx2NUT2XcSGCGv9ja-X6ntyhDh7xBROuJGqFXBlC4Q1yuPQGe9VzeHwOJz6Pbghd/s320/DynamicChartCode04.png" width="313" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />Select <u>T</u>ext option in "Query Type" and type following query in Query window:<br /><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Red'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'DarkOrange'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Green'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Blue'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Olive'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'SeaGreen'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Brown'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Gray'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Tomato'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">ColorName</span></span></span><br /><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"></span></span></span><br />Click OK to proceed.<br /><br /><br />Create one more dataset using following query and name it Chart.ds:<br /><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 2010 </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">[Year]</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 12000 </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Amount</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 2011 </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">[Year]</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 15000 </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Amount</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">UNION</span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 2012 </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">AS</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">[Year]</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 13000 </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Amount</span></span></span><br /><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"></span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span><br /><br /><strong>Step6</strong>. Drag and drop "3D Cylinder" bar chart from toolbox. Drag and drop Amount field from Chart.ds to value field (Y axis) and Year field to Category Groups as shown below.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtIjh_e1mG6SWkwoPh5y-2PoL8e5S2FnMUHJGEDwI6DeRzL2Pffl38Mn6m1VEDsLnj38Zf3N6WEgpZj0g145Toae8-g_dFyVJRc98BFOWFuUeZk8h58qOV43prM9-WBl6PZPnJUkV1HkVD/s1600/DynamicChartCode05.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="243" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtIjh_e1mG6SWkwoPh5y-2PoL8e5S2FnMUHJGEDwI6DeRzL2Pffl38Mn6m1VEDsLnj38Zf3N6WEgpZj0g145Toae8-g_dFyVJRc98BFOWFuUeZk8h58qOV43prM9-WBl6PZPnJUkV1HkVD/s640/DynamicChartCode05.png" width="640" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><u>To make the chart more meaningful and dainty, do following formatting:</u><br />1. Replace Chart Title with "Year vs Amount".<br />2. Replace Y Axis Title with Amount.<br />3. Repalce X Axis Title with Year.<br />4. Remove the Chart Legend.<br />5. Change the font size and color as you wish.<br />6. Right click on the bar and select "Show Data Labels". Select Times New Roman in data labels font because numbers are better visible in this font.<br /><br />After incorporating all the above changes, click on Preview tab to view the report. My report looks like one shown below:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiFhY7gvXiZTR9GB1VXwJjfQAMNbjuaDZ0juFtgbTf46ZY3AslCJEF9V10Z0dIz1VpOyK73MGCaQ2mccm_RY94KbJpCsL8eDkzmgGayhtWHXmMKsakf-y0gzJicbKUVG-ZyqOOXOOKjN9B/s1600/DynamicChartCode06.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="215" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiFhY7gvXiZTR9GB1VXwJjfQAMNbjuaDZ0juFtgbTf46ZY3AslCJEF9V10Z0dIz1VpOyK73MGCaQ2mccm_RY94KbJpCsL8eDkzmgGayhtWHXmMKsakf-y0gzJicbKUVG-ZyqOOXOOKjN9B/s400/DynamicChartCode06.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong></strong><br /><strong>Step7</strong>. Now I will explain how to change the chart color at run-time.<br />First of all, I will create a report parameter for dynamic color. Click on <strong>Parameters</strong> folders in Report Data and then click on <strong>Add Parameter</strong>... Define pColor as report parameter Name and Color as Prompt. Select parameter visibility <strong>Hidden</strong>. You can keep it as Visible if you wish to do so.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxqdS-oS84WnQQUN1FtC5HkEJz6ncNsLue1DvxaVTQ1-EhCYLp8vSFl-NGXhlyGxAKR_1EcDm-LODYAp-k_Thjtxlel1RDa3Au86c6vIbABJkbTkofsRlyVX84sUKYUtwQNZukuHzSvfpT/s1600/DynamicChartCode11.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="328" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxqdS-oS84WnQQUN1FtC5HkEJz6ncNsLue1DvxaVTQ1-EhCYLp8vSFl-NGXhlyGxAKR_1EcDm-LODYAp-k_Thjtxlel1RDa3Au86c6vIbABJkbTkofsRlyVX84sUKYUtwQNZukuHzSvfpT/s400/DynamicChartCode11.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />Click on <strong>Available Values</strong> under Report Parameter Properties window. Select "Get values from a query" option under "Select from one of the following options". Select <strong>ColorPalette</strong> in Dataset box, <strong>ColorName</strong> in "<u>V</u>alue field", and <strong>ColorName</strong> in "<u>L</u>abel field".<br /><br />Click on <strong>Default Values</strong> under Report Parameter Properties window. Select "Get values from a query" option under "Select from one of the following options". Select <strong>ColorPalette</strong> in Dataset box, and <strong>ColorName</strong> in "<u>V</u>alue field". Click OK to proceed.<br /><br /><br /><strong>Step8</strong>. Drag and drop <strong>Table</strong> control from toolbox.<br /><u>Do set following properties for table control.</u><br />a) Table control will have three default columns. Delete one column.<br />b) Merge Table Header and write "Color Palette" in the textbox.<br />c) Write following expression in the second column of Table Details.<br /><span style="background-color: #eeeeee;"><span style="font-family: Consolas;"><span style="font-family: Consolas;">=IIF(Parameters!pColor.Value=Fields!ColorName.Value,</span></span><span style="color: #a31515; font-family: Consolas;"><span style="color: #a31515; font-family: Consolas;"><span style="color: #a31515; font-family: Consolas;">"◄"</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">,</span></span><span style="color: #a31515; font-family: Consolas;"><span style="color: #a31515; font-family: Consolas;"><span style="color: #a31515; font-family: Consolas;">""</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">)</span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span>and write following expression in background property of same text box: <br /><span style="background-color: #eeeeee; font-family: Consolas;">=Fields!ColorName.Value</span><br /><br />d) Select Table Details and then right click --> select "Row Group" --> select "Group properties"<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4Ya5hE0s2HZkwQvnM4I5ps0jSQLo4KH0NHv6wnIpnFJBPghgzGnNgs_N7gURRNvKzylQ1jWw5_CMiyv8-2eetJEeuR62McxBkCk7ngbGl8h9h0tbEN0Nth3YfCqI6PgHjR-7IoutsuF28/s1600/DynamicChartCode07.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="197" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4Ya5hE0s2HZkwQvnM4I5ps0jSQLo4KH0NHv6wnIpnFJBPghgzGnNgs_N7gURRNvKzylQ1jWw5_CMiyv8-2eetJEeuR62McxBkCk7ngbGl8h9h0tbEN0Nth3YfCqI6PgHjR-7IoutsuF28/s400/DynamicChartCode07.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />e) In "Group Properties" window, click on expression button under "Group on" box and write following expression <span style="background-color: #eeeeee; font-family: Consolas;">=Fields!ColorName.Value</span>.<br /><span style="background-color: #eeeeee; font-family: Consolas; font-size: x-small;"></span><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj8MjR2UjaDODfmZDIEXUZ4Qz1pRc-_TIYO0ZH8SVSSJVB8uip_rTuT2jgVDECxxVyob-slTpcGexJJ_5dd84_fsHJS-yQQqcr0SmiZbLFv8XO168Y28qMsZaducn2SI3PZiDQ7YM0Kclt/s1600/DynamicChartCode08.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="335" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj8MjR2UjaDODfmZDIEXUZ4Qz1pRc-_TIYO0ZH8SVSSJVB8uip_rTuT2jgVDECxxVyob-slTpcGexJJ_5dd84_fsHJS-yQQqcr0SmiZbLFv8XO168Y28qMsZaducn2SI3PZiDQ7YM0Kclt/s400/DynamicChartCode08.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />f) Select first text box of Table Details and then right click to select "Test Box Properties" as highlighted below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9903Wk2iD2qJuL2n-gR4Ay-00yPaSWYEFwuTaODs_TNPvdegKXu90sN-nOGiHBZjtlzAMWNrq4mnyS6OfeKazM-vwvlvXIHoKU8ODBIDA8vmjc5FimVUIHZhBS4cdMDZF6B94VttZv3zL/s1600/DynamicChartCode09.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9903Wk2iD2qJuL2n-gR4Ay-00yPaSWYEFwuTaODs_TNPvdegKXu90sN-nOGiHBZjtlzAMWNrq4mnyS6OfeKazM-vwvlvXIHoKU8ODBIDA8vmjc5FimVUIHZhBS4cdMDZF6B94VttZv3zL/s1600/DynamicChartCode09.png" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />g) in "Text Box Properties" dialogue box, click on <strong>Action</strong> and select "Go to report" under "Enable as an action" and "ChartColorCode" in "Specify a report" box. Also select report parameter <strong>pColor</strong> in Name and <strong>[ColorName]</strong> in Value as shown below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRK3OZGDSTabnU1HfYZR7DuSxOoVzmBKcYsNzLvICgFM0NPHw51Tnqtt3a1BMDDExD44KVb10YYB3Nch8hkHuIatuBL-AXB3iKFIomoWUX6HliQX-hFQ7WV7VNcdrIZIR3ys0VmrX0pzd_/s1600/DynamicChartCode10.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="291" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRK3OZGDSTabnU1HfYZR7DuSxOoVzmBKcYsNzLvICgFM0NPHw51Tnqtt3a1BMDDExD44KVb10YYB3Nch8hkHuIatuBL-AXB3iKFIomoWUX6HliQX-hFQ7WV7VNcdrIZIR3ys0VmrX0pzd_/s320/DynamicChartCode10.png" width="320" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong></strong><br /><strong></strong><br /><strong>Step9</strong>. Now we are at the final step where we need to change the properties of bar chart to change the color at run time. Right click on bar chart and select "Series Properties".<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicftgaTZW7sz9hLbIMyI-FF03K_B3OTu6uEhFmw3UUJocdSB5ueHHE_6sBDg-3Ou5YBR1EHcW4ZTW4c7DpDoFgXS0F5reuCRKq4vr8vG_vm6pN7eH1BwCJ64OJGyOLvFkjp3YviBVccg6v/s1600/DynamicChartCode12.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="167" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicftgaTZW7sz9hLbIMyI-FF03K_B3OTu6uEhFmw3UUJocdSB5ueHHE_6sBDg-3Ou5YBR1EHcW4ZTW4c7DpDoFgXS0F5reuCRKq4vr8vG_vm6pN7eH1BwCJ64OJGyOLvFkjp3YviBVccg6v/s320/DynamicChartCode12.png" width="320" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />In "Series Properties" window, click on <strong>Fill</strong>. and then click on <strong>expression</strong> button to open Expression window. Double click on pColor under parameter or write following expression manually as shown below:<br /><span style="font-family: Consolas;"><span style="background-color: #eeeeee; font-family: Consolas;">=Parameters!pColor.Value</span></span><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVtTakJo0h7FSAyhlOwBUo2dqY3bSkmxj4NiKTpd1aE-Wpcj4ukVAOMXKVXqDwr_7p1aQnlENuQ3Wy_6BUk-OZMgUnV6sl_rOZf-Ky3IsaDpQc4RW7ZU6ns1LpNe_VL3_hmgKwzQ1I9wEw/s1600/DynamicChartCode13.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="227" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVtTakJo0h7FSAyhlOwBUo2dqY3bSkmxj4NiKTpd1aE-Wpcj4ukVAOMXKVXqDwr_7p1aQnlENuQ3Wy_6BUk-OZMgUnV6sl_rOZf-Ky3IsaDpQc4RW7ZU6ns1LpNe_VL3_hmgKwzQ1I9wEw/s320/DynamicChartCode13.png" width="320" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong>Step10</strong>. Its time to run the report and see the results.<br /><br /><strong>First Preview</strong>:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJUaSakKcD9MCZ7PSrixoMlbbwo1SlYHWHC90Jw2nLJv-yxYHCx8BZf5uDu5qrFotkCrgmuLpLAsNkAE0IKWQVqdf7xRykgYiq6asbMeqgWREn_5YXyMU8ZRpAiXqtpWBKQgC-w_EOvvym/s1600/DynamicChartCode14.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJUaSakKcD9MCZ7PSrixoMlbbwo1SlYHWHC90Jw2nLJv-yxYHCx8BZf5uDu5qrFotkCrgmuLpLAsNkAE0IKWQVqdf7xRykgYiq6asbMeqgWREn_5YXyMU8ZRpAiXqtpWBKQgC-w_EOvvym/s400/DynamicChartCode14.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong>Second Preview</strong>: Following report will be displayed once we click on <strong>Red</strong> color under:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinpfBIhCAOiSmVU2E6o-uIucuTg5uGSpK_KfqAffFDhtPN57Hon9q1p4JeEMeZZR3BcWj_Tquwf6FO59Uh-V_Y-oauLXBDxDRNTMQqg38a8o1F84MMMQY4cvUrisO0VP1dhuwt3eBXPaDP/s1600/DynamicChartCode15.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="187" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinpfBIhCAOiSmVU2E6o-uIucuTg5uGSpK_KfqAffFDhtPN57Hon9q1p4JeEMeZZR3BcWj_Tquwf6FO59Uh-V_Y-oauLXBDxDRNTMQqg38a8o1F84MMMQY4cvUrisO0VP1dhuwt3eBXPaDP/s400/DynamicChartCode15.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong>Third Preview</strong>: Following report will be displayed once we click on <strong>DarkOrange</strong> color under:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirdVsQjElKthO7sgXwhBHNRx6t4synGLH5QmKQz2xizZ03e8wNFIBigDqqrdjusds0rRwwN7Q4MiuCB_MT7GfGBhEP2VdW250uYxYGSbZ-VjzV4AKr7pvxFrkYIk2IfqnYWxTeFZyUqsmV/s1600/DynamicChartCode16.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="187" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirdVsQjElKthO7sgXwhBHNRx6t4synGLH5QmKQz2xizZ03e8wNFIBigDqqrdjusds0rRwwN7Q4MiuCB_MT7GfGBhEP2VdW250uYxYGSbZ-VjzV4AKr7pvxFrkYIk2IfqnYWxTeFZyUqsmV/s400/DynamicChartCode16.png" width="400" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />I hope you like this article!<br /><br /> </div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com1tag:blogger.com,1999:blog-5098208425613902582.post-87051738190676308942012-10-27T22:00:00.000-07:002013-03-23T13:09:38.932-07:00SSIS Logging<div dir="ltr" style="text-align: left;" trbidi="on">In this article I'm writting about <strong>Logging</strong> features in SQL Server Integration Services (SSIS).<br /><br />I'hv been using SSIS since last 6-7 years and I have had to implement <em>Logging Mechanism</em> in almost all the projects to track/debug the execution of each and every task/event used in the package. Some of you may say its pretty easy to implement - still I guess we need to take care of logging because some of the things are not so easy.<br /><br />Integration Services includes logging features that write log entries whenever run-time events occur but the good thing is that it can also write <strong>custom messages</strong>. Also SSIS supports a diverse set of log providers that can write log entries to: Text files, SQL Server Profiler, SQL Server, Windows Event Log, or XML files.<br /><br />My favourite log is SQL Sevrer because using sql table I can write my own queries to find logging info related to specific task/event or any failure easily.<br /><br />Basically SSIS logs are associated with packages and are configured at the package level. The task(s)/container(s) in a package can be enabled for logging even if the package itself is not e.g enable logging on an Execute SQL task without enabling logging on the parent package. Also package/container/task can write to multiple logs. You can enable logging on the package only, however you can choose to enable logging on any individual task/container.<br /><br />You can select a level of logging as per your requirement by specifying the events to log and the information to log for each event, however some events provide more useful information than others.<br /><br />I'll explain Logging using SQL Server 2012. <br /><em>Note: SSIS 2005 uses table <span style="font-size: x-small;"><strong>sysDtsLog90</strong> </span>for logging and SSIS 2008 & SSIS 2012 use <span style="font-size: x-small;"><strong>sysSSISLog</strong> table </span>for logging.</em><br /><br />Below is the description of each element in the log schema:<br /><table border="1"><tbody><tr><th><span style="color: #0c343d;">Element</span></th><th><span style="color: #0c343d;">Description</span></th></tr><tr><td><span style="color: #660000;">Computer</span></td><td>The name of the computer on which the log event occurred.</td></tr><tr><td><span style="color: #660000;">Operator</span></td><td>The identity of the user who executed the package.</td></tr><tr><td><span style="color: #660000;">Source</span></td><td>The name of the container or task in which the log event occurred.</td></tr><tr><td><span style="color: #660000;">SourceID</span></td><td>The unique identifier of the package; <br />the For Loop, Foreach Loop, or Sequence container; <br />or the task in which the log event occurred.</td></tr><tr><td><span style="color: #660000;">ExecutionID</span></td><td>The GUID of the package execution instance.</td></tr><tr><td><span style="color: #660000;">StartTime</span></td><td>The time at which the container or task starts to run.</td></tr><tr><td><span style="color: #660000;">EndTime</span></td><td>The time at which the container or task stops running.</td></tr><tr><td><span style="color: #660000;">DataCode</span></td><td>An integer value from the DTSExecResult enumeration <br />that indicates the result of running task:<br /><ul><li>0 - Success</li><li>1 - Failure</li><li>2 - Completed</li><li>3 - Canceled</li></ul></td></tr><tr><td><span style="color: #660000;">DataBytes</span></td><td>A byte array specific to the log entry. <br />The meaning of this field varies by log entry.</td></tr><tr><td><span style="color: #660000;">Message</span></td><td>A message associated with the log entry.</td></tr></tbody></table><br />The following table describes the predefined events that can be enabled to write log entries when run-time events occur:<br /><table border="1"><tbody><tr><th>Events</th><th>Description</th></tr><tr><td>OnError</td><td>Writes a log entry when an error occurs.</td></tr><tr><td>OnExecStatusChanged</td><td>Writes a log entry when the execution status of the executable changes.</td></tr><tr><td>OnInformation</td><td>Writes a log entry during the validation and execution of an executable to report information.</td></tr><tr><td>OnPostExecute</td><td>Writes a log entry immediately after the executable has finished running.</td></tr><tr><td>OnPostValidate</td><td>Writes a log entry when the validation of the executable finishes.</td></tr><tr><td>OnPreExecute</td><td>Writes a log entry immediately before the executable runs.</td></tr><tr><td>OnPreValidate</td><td>Writes a log entry when the validation of the executable starts.</td></tr><tr><td>OnProgress</td><td>Writes a log entry when measurable progress is made by the executable.</td></tr><tr><td>OnQueryCancel</td><td>Writes a log entry at any juncture in the task processing where it is feasible to cancel execution.</td></tr><tr><td>OnTaskFailed</td><td>Writes a log entry when a task fails.</td></tr><tr><td>OnVariableValueChanged</td><td>Writes a log entry when the value of a variable changes.</td></tr><tr><td>OnWarning</td><td>Writes a log entry when a warning occurs.</td></tr><tr><td>PipelineComponentTime</td><td>For each data flow component, writes a log entry for each phase of validation and execution. The log entry specifies the processing time for each phase.</td></tr><tr><td>Diagnostic</td><td>Writes a log entry that provides diagnostic information e.g. you can log a message before and after every call to an external data provider.</td></tr></tbody></table><br /><br /><strong><span style="font-size: large;">Implementing Logging in SSIS 2012</span></strong><br /><strong></strong><br />To implement the SSIS logging, follow these steps:<br /><br /><strong>Step1.</strong> Create a <em>Connection Manager </em>for logging database. Right click on Connection Managers area and click on New <strong>OLE DB Connections...</strong> as shown below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNl8vWYD7nxy7v7A67TvrTwF8M0f9iLbkEre_mTCNDkWc5yURx_Q-b6lT42jS3z9U9rIS3xLS61SLPPkC8KfFNmCKvygA_eMTmQBSj9zzzAZxL1TB96B0GTT93TGccNrN0gSgDcpWQyqzL/s1600/Logging01.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="285" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNl8vWYD7nxy7v7A67TvrTwF8M0f9iLbkEre_mTCNDkWc5yURx_Q-b6lT42jS3z9U9rIS3xLS61SLPPkC8KfFNmCKvygA_eMTmQBSj9zzzAZxL1TB96B0GTT93TGccNrN0gSgDcpWQyqzL/s320/Logging01.PNG" width="320" /></a></div><br /><strong>Step2.</strong> In the "Configure OLE DB Connection Manager" click on Create button. Now select <strong>Server Name</strong> and database name from <strong>Connect a database</strong>. I am using <strong>(Local)</strong> server and <strong>Test</strong> database. Click on Test Connection button to verify the connection.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVIRwxBpYCwI9UpDvyrrQNKkFkJ0wOgyIZ3SgGtuoqxt-2mXT3vJl5v3ahycG-PV9STjiW5FiLrgiOu4-jTgfp_C21zr_nuGgMQLLTfrs0y7YsvyLVLUWfcC5FSPzHdmaBnrvNJBDKMNxA/s1600/Logging02.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVIRwxBpYCwI9UpDvyrrQNKkFkJ0wOgyIZ3SgGtuoqxt-2mXT3vJl5v3ahycG-PV9STjiW5FiLrgiOu4-jTgfp_C21zr_nuGgMQLLTfrs0y7YsvyLVLUWfcC5FSPzHdmaBnrvNJBDKMNxA/s320/Logging02.PNG" width="313" /></a></div><br /><br />Finally click on OK button to save the connection manager. This will create a new connection manage with ServerName.DatabaseName name. In my example, it is <strong>(local).Test</strong>. You can rename it to appropriate and meaningful name. For instance <strong>cmLogging</strong>.<br /><br /><strong>Step3.</strong> Right click anywhere on the package surface area in the Control Flow to open <strong>Configure SSIS Log: Package</strong> wizard. Check the Package folder checkbox (left side) to enable the logging. Under the "Providers and Log" tab, select "SSIS log provider for SQL Server" in <strong>Provider type</strong> and click on <strong>Add</strong> button t add this logging for the package. Finally, click on <strong>Configuration</strong> to select the logging connection manager. Select <strong>cmLogging</strong> as connection manager.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2ivlkzH1MQbev7K_4WOi5kvlz3DBpxFSHOqSMOGW5ghwaBrmsFKLIYShVadqnA-uHz3uzaBJf7GXk5XJ5zBpaqrn4JUiWO1WMYEcHPIFQ_FdF2icnfWTQk5s371Sat9JeiKpFCfdJN7YP/s1600/Logging04.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="257" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2ivlkzH1MQbev7K_4WOi5kvlz3DBpxFSHOqSMOGW5ghwaBrmsFKLIYShVadqnA-uHz3uzaBJf7GXk5XJ5zBpaqrn4JUiWO1WMYEcHPIFQ_FdF2icnfWTQk5s371Sat9JeiKpFCfdJN7YP/s320/Logging04.PNG" width="320" /></a></div><br /><strong>Step4.</strong> Select logging events.<br />To prevent log files from using large amounts of disk space, which could degrade performance, you can limit logging by selecting specific events and information items to log. For example, you can configure a log to capture only the date and the computer name along with error message. It is not a good idea to log all the events. Under "Details" tab, select required events for logging:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY48IFJpgDXIaV7jd355fPnBDEFEmRYi-yq9e0OOn0Ki-HjiSQP7db2JKex9TKbBSuE5pPwCXHwnkkAsEjmf0YFW0oQAJzs9OGpD5l1ZKU0SvMMaI4jMQf2vCcfBhbuOyE0gOFKEWjpXIb/s1600/Logging05.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="237" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY48IFJpgDXIaV7jd355fPnBDEFEmRYi-yq9e0OOn0Ki-HjiSQP7db2JKex9TKbBSuE5pPwCXHwnkkAsEjmf0YFW0oQAJzs9OGpD5l1ZKU0SvMMaI4jMQf2vCcfBhbuOyE0gOFKEWjpXIb/s320/Logging05.png" width="320" /></a></div><br /><br /><strong>Step5.</strong> Click on Advance button to set advance properties of the logging events.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRwIFZV4ua_UnG-UGKCKBlEOrcMbIl3eAELtzMobtKU1i9ev3hLoTn3LjIs6nYFoTku3yTj9-Tvq8I6OTNIjQO-0hEA6J6AWIaLV2t6pDn8MuZq_pAfER8zhdmQIs8v8rocxAO2Yu3PImd/s1600/Logging06.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="176" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRwIFZV4ua_UnG-UGKCKBlEOrcMbIl3eAELtzMobtKU1i9ev3hLoTn3LjIs6nYFoTku3yTj9-Tvq8I6OTNIjQO-0hEA6J6AWIaLV2t6pDn8MuZq_pAfER8zhdmQIs8v8rocxAO2Yu3PImd/s320/Logging06.png" width="320" /></a></div><br />Finally click on the OK button to save logging configuration.<br /><br /><strong>Step6</strong>. Now you can validate your logging information by executing the SSIS package. To get more information about hoe to execute SSIS package, click <a href="http://sql-bi-dev.blogspot.com/2012/09/different-ways-to-execute-ssis-packages.html" target="_blank">Different ways to Execute SSIS packages</a>. My package looks like the picture shown below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQrsmMccc9azDzaCcRaXSksVKNTw2AWbVpYAH8JGRvesT4T1n3v2B_jxGRQakQBFwoYX9rclZ3DjIBuxeefeACDD-IBs0VN1O3pyQojIO5CarBuCcfE__6wy6dk18c4h28XKSA7Q4z3t4K/s1600/Logging08.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQrsmMccc9azDzaCcRaXSksVKNTw2AWbVpYAH8JGRvesT4T1n3v2B_jxGRQakQBFwoYX9rclZ3DjIBuxeefeACDD-IBs0VN1O3pyQojIO5CarBuCcfE__6wy6dk18c4h28XKSA7Q4z3t4K/s320/Logging08.PNG" width="271" /></a></div>You can see the log in sysSSISLog table after executing the package.<br /><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">*</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">FROM</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">Test</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">dbo</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">.</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">sysssislog</span></span></span><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsdPdHhHwqYutVNVRib1noi0lD5a-7dZtENMGfXaYlczhPq0yWD1Z9V2RgIXdf2q5ceavUuiKP1E3FmtbTYcEaTZRE4YHOzggcaEhKKdzcbfJeBhQ7_ktMlWilr9ymzdXvbBoeC8_aOGsV/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="53" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsdPdHhHwqYutVNVRib1noi0lD5a-7dZtENMGfXaYlczhPq0yWD1Z9V2RgIXdf2q5ceavUuiKP1E3FmtbTYcEaTZRE4YHOzggcaEhKKdzcbfJeBhQ7_ktMlWilr9ymzdXvbBoeC8_aOGsV/s320/1.png" width="320" /></a></div><em><span style="font-size: xx-small;"></span></em><br /><em><span style="font-size: xx-small;"></span></em><br /><em><span style="font-size: xx-small;"></span></em><br /> </div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com1tag:blogger.com,1999:blog-5098208425613902582.post-67345807644726079242012-10-01T22:00:00.000-07:002013-03-23T13:09:38.940-07:00How to find missing Identity/Sequence numbers using T-SQL?<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">SQL Developers, did you ever come across a situation where you need to find missing identity or sequence number for a given table? For instance, someone deleted few records from a table which has an IDENTITY column. Have you wondered how to find those missing rows? In this blogpost, I am going to explain different ways to <strong>find missing identity or sequence numbers</strong>.<o:p></o:p></span></span></div><br /><div class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">First I will create some sample data for demonstration purpose.<o:p></o:p></span></span></div><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-- Prepare Test data --</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SET</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">NOCOUNT</span> <span style="color: blue;">ON</span><o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">IF</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: magenta;">OBJECT_ID</span><span style="color: grey;">(</span><span style="color: red;">'dbo.TestData'</span><span style="color: grey;">)</span> <span style="color: grey;">IS</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL</span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">DROP</span> <span style="color: blue;">TABLE</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span><o:p></o:p></span><br /><br /><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">CREATE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">TABLE</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span><span style="color: blue;"> </span><span style="color: grey;">(</span><o:p></o:p></span></div><span style="font-family: Consolas; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="color: teal;">ID</span> <span style="color: blue;">INT</span> <span style="color: blue;">IDENTITY</span><span style="color: grey;">(</span>1<span style="color: grey;">,</span> 1<span style="color: grey;">)</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL</span><o:p></o:p></span><br /><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">)</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span><br /><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">DECLARE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">@Counter</span> <span style="color: blue;">INT</span> <span style="color: grey;">=</span> 1<o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">WHILE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">@Counter</span> <span style="color: grey;"><=</span> 15<o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">BEGIN</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span><br /><span style="font-family: Consolas; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">INSERT</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span> <span style="color: blue;">DEFAULT</span> <span style="color: blue;">VALUES</span><o:p></o:p></span><br /><span style="font-family: Consolas; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">SET</span> <span style="color: teal;">@Counter</span> <span style="color: grey;">+=</span> 1<o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">END</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span><br /><span style="font-family: Consolas; font-size: 9.5pt;"><o:p> </o:p></span><br /><br /><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">ID</span> <span style="color: blue;">FROM</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span></span><br /><span style="color: teal; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span> </div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8K_tcg_qaSSKRYou05VTKhFdGSl6t2Zuim8EThgDCFthdXfpLlDabEXo4tvDzS5IAPBOFyg-iaXjHLSxOwRmch56-tc156n8wixJDjlJjoCOpYuHo_o4QQO3Os5Nw6_TPQyzXONEV6BV_/s1600/MissingIdentity1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8K_tcg_qaSSKRYou05VTKhFdGSl6t2Zuim8EThgDCFthdXfpLlDabEXo4tvDzS5IAPBOFyg-iaXjHLSxOwRmch56-tc156n8wixJDjlJjoCOpYuHo_o4QQO3Os5Nw6_TPQyzXONEV6BV_/s1600/MissingIdentity1.png" /></a></div><div class="separator" style="clear: both; text-align: center;"> </div><div class="separator" style="clear: both; text-align: center;"> </div><div class="separator" style="clear: both; text-align: center;"> </div><div class="separator" style="clear: both; text-align: center;"> </div><span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">Now lets delete some rows manualy:<o:p></o:p></span></span><br /><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-- Now delete some records (IDs)</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">DELETE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span> <span style="color: blue;">WHERE</span> <span style="color: teal;">ID</span> <span style="color: grey;">IN</span><span style="color: blue;"> </span><span style="color: grey;">(</span>3<span style="color: grey;">,</span>7<span style="color: grey;">,</span>8<span style="color: grey;">,</span>10<span style="color: grey;">,</span>12<span style="color: grey;">,</span>13<span style="color: grey;">)</span><o:p></o:p></span><br /><span style="font-family: Consolas; font-size: 9.5pt;"><o:p> </o:p></span><br /><span style="color: green; font-family: Consolas; font-size: 9.5pt;">--Verifiy the data</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">ID</span> <span style="color: blue;">FROM</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span><o:p></o:p></span><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkwChcyj6n4aqh4j02l0qqvkT8dQ57_weZJatFCzGruIQZiQobwu3BwDXzZPJ8l0yHh0fO8aUlCy9KErT80F12P-BuZRvsRHZg35iODPKY1oDDAuTRx0n6ps3THhLc1Gh5qLTn5vfwyYQM/s1600/MissingIdentity2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkwChcyj6n4aqh4j02l0qqvkT8dQ57_weZJatFCzGruIQZiQobwu3BwDXzZPJ8l0yHh0fO8aUlCy9KErT80F12P-BuZRvsRHZg35iODPKY1oDDAuTRx0n6ps3THhLc1Gh5qLTn5vfwyYQM/s1600/MissingIdentity2.png" /></a></div><div class="separator" style="clear: both; text-align: center;"> </div><div class="separator" style="clear: both; text-align: left;"><span style="font-size: 12pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">Below are three different ways to identity missing values.</span></span></div><div class="separator" style="clear: both; text-align: left;"> </div><div class="MsoNormal" style="margin: 0in 0in 10pt;"><b style="mso-bidi-font-weight: normal;"><span style="font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">Find missing sequence numbers using Ranking Function:</span></span></b></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-------------------------------------------</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-- Option 1: Using Ranking function</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-------------------------------------------</span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">DECLARE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">@MaxID</span> <span style="color: blue;">INT</span> <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">SELECT</span> <span style="color: magenta;">MAX</span><span style="color: grey;">(</span><span style="color: teal;">ID</span><span style="color: grey;">)</span> <span style="color: blue;">FROM</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span><span style="color: grey;">)</span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"></span><br /><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">SeqID</span> <span style="color: blue;">AS</span> <span style="color: teal;">MissingSeqID</span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">FROM </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: magenta;">ROW_NUMBER</span><span style="color: grey;">()</span> <span style="color: blue;">OVER </span><span style="color: grey;">(</span><span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: teal;">column_id</span><span style="color: grey;">)</span> <span style="color: teal;">SeqID</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">columns</span><span style="color: grey;">)</span> <span style="color: teal;">LkUp</span></span><br /><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">LEFT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">JOIN</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span> <span style="color: teal;">t</span> <span style="color: blue;">ON</span> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">=</span> <span style="color: teal;">LkUp</span><span style="color: grey;">.</span><span style="color: teal;">SeqID</span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">WHERE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">is</span><span style="color: grey;">null</span> <span style="color: grey;">and</span> <span style="color: teal;">SeqID</span> <span style="color: grey;"><</span> <span style="color: teal;">@MaxID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Here is the output:</span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span> </div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBqoViPd6Rgr5awO-RkNF0jL-asBPcZ1rmcPy7PZ3qijck5RcPjKx-y4E5jwxTR4oc-Ml-y1npTpU_r7L6Zpi1sTcVJ5upqLINaOynxNQQtxvZAkK_hvn7brLT0gLSGQjB3C7R5w22khNp/s1600/MissingIdentity3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBqoViPd6Rgr5awO-RkNF0jL-asBPcZ1rmcPy7PZ3qijck5RcPjKx-y4E5jwxTR4oc-Ml-y1npTpU_r7L6Zpi1sTcVJ5upqLINaOynxNQQtxvZAkK_hvn7brLT0gLSGQjB3C7R5w22khNp/s1600/MissingIdentity3.png" /></a></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: "Calibri","sans-serif"; font-size: 12pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span> <span style="color: green; font-family: Consolas; font-size: 9.5pt;">-- If there are less records in sys.columns and <o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-- you need need larger result then use CROSS JOIN</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">SeqID</span> <span style="color: blue;">AS</span> <span style="color: teal;">MissingSeqID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">FROM </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: magenta;">ROW_NUMBER</span><span style="color: grey;">()</span> <span style="color: blue;">OVER </span><span style="color: grey;">(</span><span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: teal;">c1</span><span style="color: grey;">.</span><span style="color: teal;">column_id</span><span style="color: grey;">)</span> <span style="color: teal;">SeqID</span> <o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">FROM</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">columns</span> <span style="color: teal;">c1</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">CROSS</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">JOIN</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">columns</span> <span style="color: teal;">c2</span><span style="color: grey;">)</span> <span style="color: teal;">LkUp</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">LEFT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">JOIN</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span> <span style="color: teal;">t</span> <span style="color: blue;">ON</span> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">=</span> <span style="color: teal;">LkUp</span><span style="color: grey;">.</span><span style="color: teal;">SeqID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">WHERE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">is</span><span style="color: grey;">null</span> <span style="color: grey;">and</span> <span style="color: teal;">SeqID</span> <span style="color: grey;"><</span> <span style="color: teal;">@MaxID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; font-size: 9.5pt;"><o:p> </o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="margin: 0in 0in 10pt;"><b style="mso-bidi-font-weight: normal;"><span style="font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"></span></b><br /><b style="mso-bidi-font-weight: normal;"><span style="font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt;">Find missing sequence numbers using CTE:<o:p></o:p></span></b></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-------------------------------------------</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-- Option 2: Using Common Table Expression</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-------------------------------------------</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">DECLARE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">@MaxID</span> <span style="color: blue;">INT</span> <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">SELECT</span> <span style="color: magenta;">MAX</span><span style="color: grey;">(</span><span style="color: teal;">ID</span><span style="color: grey;">)</span> <span style="color: blue;">FROM</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span><span style="color: grey;">)</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">;</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">WITH</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">CTE</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: teal;">MissingSeqID</span><span style="color: grey;">,</span> <span style="color: teal;">MaxID</span><span style="color: grey;">)</span> <o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">AS </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">(</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="font-family: Consolas; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">SELECT</span> 1 <span style="color: blue;">AS</span> <span style="color: teal;">MissingSeqID</span><span style="color: grey;">,</span> <span style="color: teal;">@MaxID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="font-family: Consolas; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">UNION</span> <span style="color: grey;">ALL</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="font-family: Consolas; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">SELECT</span> <span style="color: teal;">MissingSeqID</span> <span style="color: grey;">+</span> 1<span style="color: grey;">,</span> <span style="color: teal;">MaxID</span> <span style="color: blue;">FROM</span> <span style="color: teal;">CTE</span> <span style="color: blue;">WHERE</span> <span style="color: teal;">MissingSeqID</span> <span style="color: grey;"><</span> <span style="color: teal;">MaxID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="font-family: Consolas; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">)</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">MissingSeqID</span> <span style="color: blue;">FROM</span> <span style="color: teal;">CTE</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">LEFT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">JOIN</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span> <span style="color: teal;">t</span> <span style="color: blue;">on</span> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">=</span> <span style="color: teal;">CTE</span><span style="color: grey;">.</span><span style="color: teal;">MissingSeqID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">WHERE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">is</span><span style="color: grey;">NULL</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">GO</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; font-size: 9.5pt;"><o:p> </o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="separator" style="clear: both; text-align: left;"> </div><div class="MsoNormal" style="margin: 0in 0in 10pt;"><b style="mso-bidi-font-weight: normal;"><span style="font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt;">Find missing sequence numbers using <a href="http://sql-question.blogspot.com/2012/10/what-is-tally-table-in-sql-server.html" target="_blank">Tally Table</a>:</span></b><br /><span style="font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-size: small;"><span style="font-family: Calibri;">This is the most prefered way out of all the above options.</span></span></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-------------------------------------------</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-- Option 3: Using Tally Table</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt;">-------------------------------------------</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">DECLARE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">@MaxID</span> <span style="color: blue;">INT</span> <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">SELECT</span> <span style="color: magenta;">MAX</span><span style="color: grey;">(</span><span style="color: teal;">ID</span><span style="color: grey;">)</span> <span style="color: blue;">FROM</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span><span style="color: grey;">)</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">SELECT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span><span style="mso-spacerun: yes;"> </span><span style="color: teal;">MissingSeqID</span> <span style="color: blue;">FROM</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">Tally</span> <span style="color: teal;">t</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">LEFT</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">JOIN</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">TestData</span> <span style="color: teal;">td</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">ON</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">td</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">=</span> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">WHERE</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">td</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;">IS</span> <span style="color: grey;">NULL</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">AND</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: teal;">t</span><span style="color: grey;">.</span><span style="color: teal;">ID</span> <span style="color: grey;"><</span><span style="color: teal;">@MaxID</span><o:p></o:p></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times New Roman;"> </span></div><div class="separator" style="clear: both; text-align: center;"> </div><div class="separator" style="clear: both; text-align: center;"></div> </div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com5tag:blogger.com,1999:blog-5098208425613902582.post-66401131208217566942012-09-16T19:56:00.000-07:002013-03-23T13:09:38.949-07:00Different ways to Execute SSIS Packages<div dir="ltr" style="text-align: left;" trbidi="on">We have the following ways to execute SSIS packages:<br /><ul style="text-align: left;"><li>DTExec Command Line Utility</li><li>DTExecUI Windows Application</li><li>SQL Server Agent</li></ul><span style="font-size: x-small;"></span><br /><strong>DTExec Command Line Utility</strong><br />SQL Server provides the command line tool <strong>DTExec.exe</strong> which can be used to execute an SSIS package. DTExec can be run from a Command Prompt or from a batch (.BAT) file.<br />To begin, open a Command Prompt and navigate to the project folder as shown below (I am taking an example of SalesForcastInput package from local directory "<em><span style="color: #073763;">D:\SSIS\Hari\Sample\SSIS-Sample1\SalesForcastInput.dtsx</span></em>"):<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXjWv_L9ISu5RH9t3W3lZUcD7v9HxTI5thMUAt7sDcDcom16RJ3rZxI0vtyQdNzhRNkU8AUBdlsAX8kuEbJFkxuebiA1w2MebaxO8se62ZEQps6jdY893k1YfxgSr5lTj5uTTgT0K3nMq0/s1600/ExecuteSSIS1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="52" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXjWv_L9ISu5RH9t3W3lZUcD7v9HxTI5thMUAt7sDcDcom16RJ3rZxI0vtyQdNzhRNkU8AUBdlsAX8kuEbJFkxuebiA1w2MebaxO8se62ZEQps6jdY893k1YfxgSr5lTj5uTTgT0K3nMq0/s320/ExecuteSSIS1.png" width="320" /></a></div><br /><br /><br /><br /><br />Now type the following command to execute the SalesForecastInput.dtsx package:<br /><br /><span style="background-color: black; color: white;">DTEXEC /FILE SalesForecastInput.dtsx</span><br /><br />To see the complete list of command line options for DTEXEC, type following:<br /><span style="background-color: black; color: white;">DTEXEC /? </span><br /><br /><span style="color: black;"></span><br /><span style="color: black;">It is not necessary to navigate command prompt to package directory before executing <strong>DTExec</strong> command; You can give the full path of your package as shown below:</span><br /><span style="background-color: black; color: white;">DTExec /f "D:\SSIS\Hari\Sample\SSIS-Sample1\SalesForcastInput.dtsx" /conf "D:\SSIS\Hari\Sample\SSIS-Sample1\SalesForcastInput.dtsConfig" /M -1</span><br /><br />Here, /f (/File) parameter used to load the package that is saved in the file system in your system. Likewise, /conf (/ConfigFile) parameter used to load the configuration file that is saved in the file system in your system. /M (/MaxConcurrent) specifies the number of executable files that the package can run concurrently.<br /><br />Click <a href="http://msdn.microsoft.com/en-us/library/ms162810(v=SQL.105).aspx" target="_blank">here</a> for more information about DTExec utility and it's parameters.<br /><br /><strong></strong><br /><strong>DTExecUI Windows Application</strong><br /><strong></strong><br />SQL Server includes the Windows application <strong>DTExecUI.exe</strong> which can be used to execute an SSIS package. DTExecUI provides a graphical user interface that can be used to specify the various options to be set when executing an SSIS package. You can launch DTEXECUI by double-clicking on an SSIS package file (.dtsx).<br />To begin, navigate to the your project folder. Double-click on the package (For instance, SalesForecastInput.dtsx in my example) and you will see the following multi-page dialog displayed:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbaHJJsI-bqsZhT2IsBG4b-A4Mmke7EqQNipFQF0jM6oa5nuepFW1jJbvGxEU7LztI5jgPQudFDrGC2M7UZmXnCYhfjalcFCK3efYYQaqHvxEQjNeFlOWAKRnMbOSrBkmejTDAIdzWd0a6/s1600/ExecuteSSIS2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="272" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbaHJJsI-bqsZhT2IsBG4b-A4Mmke7EqQNipFQF0jM6oa5nuepFW1jJbvGxEU7LztI5jgPQudFDrGC2M7UZmXnCYhfjalcFCK3efYYQaqHvxEQjNeFlOWAKRnMbOSrBkmejTDAIdzWd0a6/s320/ExecuteSSIS2.png" width="320" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />As you can see there are many settings available when you use this utility. As a general rule you can simply click the Execute button to run your package. You can also fine tune your execution by clicking through the various screens and entering your own settings. After changing the settings click on Command Line which will show you the DTExec command line based on the settings you have chosen.<br /><em><strong>Note</strong>: If you have a configuration file which is not configured at package level, then do not forget to add the configuration file through <strong>Configurations</strong> setting.</em><br /><strong></strong><br /><br /><strong>Scheduling SSIS Package through SQL Server Agent</strong><br /><br />SQL Server Agent includes the SQL Server Integration Services Package job step type which allows you to execute an SSIS package in a SQL Server Agent job step. This can be especially handy as it allows you to schedule the execution of SSIS package so that it runs without any user interaction.<br />To begin, open <strong>SQL Server Management Studio</strong> (SSMS), connect to the Database Engine, and drill down to the <strong>SQL Server Agent</strong> node in the Object Explorer. Right click on the <strong>Jobs</strong> node and select <strong>New Job</strong> from the popup menu. Go to the <strong>Steps</strong> page, click <strong>New</strong>, and fill in the dialog as shown below:<br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF-AXz1UprlFyHbUxMoHD1xJ_jCszdZxkyeJuudxG1xsRl1mgCUKjF2gJ-yZ_bkC0TXzO6GlktTRyz8Jvg1EOx8S0MURZZxrXNEwqPicGowrQ5b751EiKTVp6UqFk0-viG_jBmyUWPvVHC/s1600/ExecuteSSIS3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="286" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF-AXz1UprlFyHbUxMoHD1xJ_jCszdZxkyeJuudxG1xsRl1mgCUKjF2gJ-yZ_bkC0TXzO6GlktTRyz8Jvg1EOx8S0MURZZxrXNEwqPicGowrQ5b751EiKTVp6UqFk0-viG_jBmyUWPvVHC/s320/ExecuteSSIS3.png" width="320" /><br /><br /><br /></a><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF-AXz1UprlFyHbUxMoHD1xJ_jCszdZxkyeJuudxG1xsRl1mgCUKjF2gJ-yZ_bkC0TXzO6GlktTRyz8Jvg1EOx8S0MURZZxrXNEwqPicGowrQ5b751EiKTVp6UqFk0-viG_jBmyUWPvVHC/s1600/ExecuteSSIS3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF-AXz1UprlFyHbUxMoHD1xJ_jCszdZxkyeJuudxG1xsRl1mgCUKjF2gJ-yZ_bkC0TXzO6GlktTRyz8Jvg1EOx8S0MURZZxrXNEwqPicGowrQ5b751EiKTVp6UqFk0-viG_jBmyUWPvVHC/s1600/ExecuteSSIS3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><div align="left"></div></a>In the above example, the SSIS package to be executed is deployed to SQL Server (i.e. the MSDB database). You can also execute packages deployed to the file system or the SSIS package store. Note that the Run as setting is the SQL Agent Service Account. This is the default setting although from a security standpoint it may not be what you want. You can setup a Proxy that allows you to give a particular credential permission to execute an SSIS package from a SQL Server Agent job step.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZokgMvK-jaWbuZUnRZAcqFUqap2gQ_CTLSvalEV-b5l_35PAqeK8ViX9OHClMNy2goAZM5JBZrIiFPb0J2cp7OCrfZDM_7gXfaZbMqURFqQch45U3nbKyx22yFQpuJc6BO17YZApCug2d/s1600/ExecuteSSIS4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a><br /></div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZokgMvK-jaWbuZUnRZAcqFUqap2gQ_CTLSvalEV-b5l_35PAqeK8ViX9OHClMNy2goAZM5JBZrIiFPb0J2cp7OCrfZDM_7gXfaZbMqURFqQch45U3nbKyx22yFQpuJc6BO17YZApCug2d/s1600/ExecuteSSIS4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZokgMvK-jaWbuZUnRZAcqFUqap2gQ_CTLSvalEV-b5l_35PAqeK8ViX9OHClMNy2goAZM5JBZrIiFPb0J2cp7OCrfZDM_7gXfaZbMqURFqQch45U3nbKyx22yFQpuJc6BO17YZApCug2d/s320/ExecuteSSIS4.png" width="290" /><br /><br /> </a><br /> </div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-84741732911684756082012-09-01T01:00:00.000-07:002013-03-23T13:09:38.955-07:00<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-size: large;"><strong>Columnstore Index</strong></span><br /><br /><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; line-height: 115%; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span style="font-family: Times New Roman; font-size: small;"> </span></span><br /><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><u>Columnstore </u>index was introduced in the SQL Server 2012 to significantly speed-up the processing time of common data warehousing queries. </span><br /><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span><br /><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Generally data warehousing workloads involve summarizing large volume of data. As you might know, we use different techniques in data-warehousing (DW) and decision support systems (DSS) to improve performance like pre-computed summary tables, indexed views, OLAP cubes etc. Although, these techniques greatly speed up query the data processing but they have some side effects. These techniques can be inflexible, hard to maintain, and must be designed specifically for specific query problem.</span><br /><span style="font-family: Calibri;"></span><br /><span style="font-family: Calibri;">Data warehousing processing overhead can be significantly reduced by using SQL Server <strong>Columnstore</strong> index. Not only that, columnstore indexes reduces the overhead of the other solutions. Columnstore indexes also enable queries to compute the results quickly so that pre-computation is not required.</span><br /><br /><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span><br /><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><strong>Characterisitcs of SQL Server Columnstore Indexes:</strong></span><br /><br /><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Columnar data format</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – unlike the traditional row based organization of data (called <span class="parameter1"><span style="font-family: "Calibri","sans-serif"; mso-ansi-font-size: 11.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><em>rowstore</em></span></span> format), <strong>columnstore</strong> indexes group and store data in one column at a time. SQL Server query processing can take advantage of this new data layout and significantly improve query execution time.<o:p></o:p></span></div><span style="font-family: Times New Roman; font-size: small;"> </span><br /><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Faster query results</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – Columnstore indexes can produce faster results for the following reasons:<o:p></o:p></span></div><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;"></span></span><br /><div style="margin-left: 1in; mso-list: l0 level2 lfo1; tab-stops: list 1.0in; text-indent: -0.25in;"><span style="color: black; font-family: "Courier New"; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Courier New";"><span style="mso-list: Ignore;">o<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Only the columns needed must be read. Therefore, less data is read from disk to memory and then from memory to processor cache.</span></div><div style="margin-left: 1in; mso-list: l0 level2 lfo1; tab-stops: list 1.0in; text-indent: -0.25in;"><span style="color: black; font-family: "Courier New"; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Courier New";"><span style="mso-list: Ignore;">o<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Columns are heavily compressed. This reduces the number of bytes that must be read and moved and hence less I/O operations.</span></div><div style="margin-left: 1in; mso-list: l0 level2 lfo1; tab-stops: list 1.0in; text-indent: -0.25in;"><span style="color: black; font-family: "Courier New"; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Courier New";"><span style="mso-list: Ignore;">o<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Most queries do not touch all columns of the table. Therefore, many columns will never be brought into memory. This, combined with excellent compression, improves buffer pool usage, which reduces total I/O.</span></div><div style="margin-left: 1in; mso-list: l0 level2 lfo1; tab-stops: list 1.0in; text-indent: -0.25in;"><span style="color: black; font-family: "Courier New"; font-size: 10pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Courier New";"><span style="mso-list: Ignore;">o<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Advanced query execution technology processes chunks of columns called <span class="parameter1"><span style="font-family: "Calibri","sans-serif"; mso-ansi-font-size: 11.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><em>batches</em></span></span> in a streamlined manner, reducing CPU usage.<o:p></o:p></span></div><div style="margin-left: 60pt; mso-list: l0 level2 lfo1; tab-stops: list 1.0in; text-align: left; text-indent: -0.25in;"><span style="font-family: Times New Roman; font-size: small;"> </span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Key columns</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – There is no concept of key columns in a columnstore index.<o:p></o:p></span></div><span style="font-family: Times New Roman; font-size: small;"> </span><br /><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Clustered index key</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – all the columns of clustered index must be present in the nonclustered columnstore index. If a column in the clustering key is not listed in the create index statement, it will be added to the columnstore index automatically.<o:p></o:p></span></div><span style="font-family: Times New Roman; font-size: small;"> </span><br /><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Partitioning</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – Columnstore indexes works with table partitioning. No change to the table partitioning syntax is required. Albeit, nonclustered columnstore index can only be created on a partitioned table if the partitioning column is part of the columnstore index.<o:p></o:p></span></div><span style="font-family: Times New Roman; font-size: small;"> </span><br /><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Record Size</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – There is no index key record size limitation on columnstore indexes.<o:p></o:p></span></div><span style="font-family: Times New Roman; font-size: small;"> </span><br /><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Query processing</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – Along with the columnstore index, SQL Server introduces batch processing to take advantage of the columnar orientation of the data. The columnstore structure and batch processing both contribute to performance gains.<o:p></o:p></span></div><span style="font-family: Times New Roman; font-size: small;"> </span><br /><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Table cannot be updated</span></span><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> – For SQL Server 2012, a table with a columnstore index cannot be updated.</span></div><span style="font-family: Times New Roman;"> </span><br /><span style="font-family: Times New Roman;"></span><br /><span style="font-family: Calibri; font-size: large;"><strong>How to create Columnstore Index:</strong></span><br /><span style="font-family: Calibri;"></span><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><span style="font-family: Calibri;"><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span></span></span></span></span></span><br /><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><span style="font-family: Calibri;"><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Columnstore index can be create using SQL Server Management Studio as well as using T-SQL. </span></span></span></span></span></span><br /><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><span style="font-family: Calibri;"><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span></span></span></span></span></span><br /><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><span style="font-family: Calibri;"><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><strong>Creating Columnstore index by using SQL Server Management Studio (SSMS):</strong></span></span></span></span></span></span><span style="font-size: small;"><span style="font-family: Times New Roman;"> </span></span><br /><span style="font-size: small;"><span style="font-family: Times New Roman;"></span></span><br /><span style="font-size: small;"><span style="font-family: Times New Roman;"><div style="margin-left: 0.5in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Segoe UI";"><span style="mso-list: Ignore;">1.<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">Open Management Studio and use Object Explorer to connect to the SQL Server Database Engine.</span></div><div style="margin-left: 0.5in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Segoe UI";"><span style="mso-list: Ignore;">2.<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">In Object Explorer, expand the instance of SQL Server, expand <span class="label">Databases</span>, expand a database, expand a table, right-click on required table, point to <span class="label">New Index</span>, and then click <span class="label">Non-Clustered Columnstore Index</span>.</span></div><div style="margin-left: 0.5in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Segoe UI";"><span style="mso-list: Ignore;">3.<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">In the <span class="label">Index name</span> dialog box, under the <span class="label">General</span> tab, type a name for the new index, and then click <span class="label">Add</span>.</span></div><div style="margin-left: 0.5in; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Segoe UI";"><span style="mso-list: Ignore;">4.<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">In the <span class="label">Select Columns</span> dialog box, select the columns to participate in the columnstore index, and then click <span class="label">OK</span> two times to create the index.</span><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLKmLfYXt4l_QQjRzYssWyg_s9YjDGMpS1aibFSzgY2xu8XQ-02gGYOgqWjoII9FZl8agG2f-TrdjAcqbwPg4Rkh6YJojrJFt5kScLHc0iHbZlez6GRjTF3TGy-VULeQwGzGZ71xDm4LYM/s1600/Columnstore+Index.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="287" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLKmLfYXt4l_QQjRzYssWyg_s9YjDGMpS1aibFSzgY2xu8XQ-02gGYOgqWjoII9FZl8agG2f-TrdjAcqbwPg4Rkh6YJojrJFt5kScLHc0iHbZlez6GRjTF3TGy-VULeQwGzGZ71xDm4LYM/s320/Columnstore+Index.PNG" width="320" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style="font-family: Calibri;"><strong>Creating Columnstore index by using T-SQL:</strong></span><span style="font-family: Times New Roman;"> </span><br /><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><span style="font-family: Calibri;"><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span></span></span></span><br /><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><span style="font-family: Calibri;"><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Create columnstore index on Employee table, name it CSI_Employee, and include all the columns!</span></span></span></span><br /><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><span style="font-family: Calibri;"><span class="label"><span style="color: black; font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"></span></span></span></span><br /> <br /><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas;">-- Check whether index CSI_Employee exists on Employee</span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas;">-- and delete if exists. </span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">IF</span><span style="font-family: Consolas;"> <span style="color: grey;">EXISTS(</span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">SELECT</span><span style="mso-spacerun: yes;"> </span><span style="color: teal;">name</span> <span style="color: blue;">FROM</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">indexes</span> </span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">WHERE</span><span style="mso-spacerun: yes;"> </span><span style="color: magenta;">object_id</span> <span style="color: grey;">=</span> <span style="color: magenta;">OBJECT_ID</span><span style="color: grey;">(</span><span style="color: red;">'dbo.Employee'</span><span style="color: grey;">)</span> </span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">AND</span><span style="mso-spacerun: yes;"> </span><span style="color: teal;">name</span> <span style="color: grey;">=</span> <span style="color: red;">'CSI_Employee'</span><span style="color: grey;">)</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">DROP</span><span style="font-family: Consolas;"> <span style="color: blue;">INDEX</span> <span style="color: teal;">CSI_Employee</span> <span style="color: blue;">ON</span> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">Employee</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">GO</span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><o:p><span style="font-family: Times New Roman;"> </span></o:p></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas;">-- Create nonclustered columnstore index CSI_Employee on Employee.</span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">CREATE</span><span style="font-family: Consolas;"> <span style="color: blue;">NONCLUSTERED</span> <span style="color: blue;">COLUMNSTORE</span><span style="color: blue;">INDEX</span> <span style="color: teal;">CSI_Employee</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">ON</span><span style="font-family: Consolas;"> <span style="color: teal;">dbo</span><span style="color: grey;">.</span><span style="color: teal;">Employee</span> </span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: grey; font-family: Consolas;">(</span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: teal;">EmployeeID</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">,</span><span style="color: teal;">FirstName</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">,</span><span style="color: teal;">MiddleName</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">,</span><span style="color: teal;">LastName</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">,</span><span style="color: teal;">DOB</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">,</span><span style="color: teal;">DepartmentID</span></span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="color: grey; font-family: Consolas;">)</span></div><div class="MsoNormal" style="background: rgb(242, 242, 242); line-height: normal; margin: 0in 0in 0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><o:p><span style="font-family: Times New Roman;"><span style="color: blue; font-family: Consolas;">GO</span></span></o:p></span><span style="font-family: Consolas;"><o:p><span style="font-family: Times New Roman;"> </span></o:p></span></div><o:p></o:p></span><br /> <b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 11.5pt; mso-bidi-font-size: 9.5pt;">Data Types<o:p></o:p></span></b><br /> <span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"></span><br /><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">Columnstore index support some data-types and doesn't support others. You need to be aware of this while creating columnstore index to avoid any run time errors.</span><br /><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"></span><br /><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">The following <strong>data types can be included</strong> in a columnstore index:</span><strong> </strong><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">char</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> and <span class="input1">varchar</span><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">nchar</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> and <span class="input1">nvarchar</span> (except <span class="input1">varchar(max)</span> and <span class="input1">nvarchar(max)</span>)<o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">decimal</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> (and <span class="input1">numeric</span>) (Except with precision greater than 18 digits.)<o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">int</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">, <span class="input1">bigint</span>, <span class="input1">smallint</span>, and <span class="input1">tinyint</span><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">float</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> (and <span class="input1">real</span>)<o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="mso-list: Ignore;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·</span></span><span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">bit</span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">money</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> and <span class="input1">smallmoney</span><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">All date and time data types (except <span class="input1">datetimeoffset</span>with scale greater than 2)<o:p></o:p></span></div><strong> </strong><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"></span><br /><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">The following <strong>data types cannot be included</strong> in a columnstore index:</span> <div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="mso-list: Ignore;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·</span></span><span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">binary</span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> and <span class="input1">varbinary</span><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">ntext</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">, <span class="input1">text</span>, and <span class="input1">image</span><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">varchar(max)</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> and <span class="input1">nvarchar(max)</span><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="mso-list: Ignore;"><span style="mso-list: Ignore;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·</span></span></span> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">uniqueidentifier</span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"><span class="input1">timestamp</span></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="mso-list: Ignore;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·</span></span><span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">sql_variant</span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"><o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">decimal</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> and <span class="input1">numeric</span> with precision greater than 18 digits<o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span class="input1"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">datetimeoffset</span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"> with scale greater than 2<o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">CLR types (<span class="input1">hierarchyid</span> and spatial types)<o:p></o:p></span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="mso-list: Ignore;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·</span></span><span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;">xml</span></div><div style="margin-left: 30pt; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt;"><o:p></o:p></span><br /> </div><div class="MsoNormal" style="margin: 0in 0in 10pt;"><a href="javascript:void(0)" title="Collapse"><b><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2; text-decoration: none; text-underline: none;"><span style="font-family: Calibri;">Columnstore Index Restrictions and Limitations</span></span></b></a><b><span style="color: #1f497d; font-size: 13pt; line-height: 115%; mso-bidi-font-size: 11.0pt; mso-themecolor: text2;"><o:p></o:p></span></b></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">There are certain restrictions and limitations on columnstore indexes which are listed below:</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Columnstor index cannot have more than 1024 columns.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Columnstor index annot be clustered or unique. Only nonclustered columnstore indexes are available.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> <span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Columnstor index c</span></span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">annot be created on a view or indexed view.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Cannot include columns of restricted data-types as mentioned above.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Cannot act as a primary key or a foreign key.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Cannot be changed using the ALTER INDEX statement. Drop and re-create the columnstore index instead.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Cannot be created with the INCLUDE keyword.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Cannot include the ASC or DESC keywords for sorting the index. Columnstore indexes are ordered according to the compression algorithms.</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt 30pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-indent: -0.25in;"><span style="color: black; font-family: Symbol; font-size: 10pt; mso-bidi-font-family: Symbol; mso-bidi-font-size: 9.5pt; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-size-adjust: none; font-stretch: normal; font: 7pt/normal "Times New Roman";"> </span></span></span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Does not use or keep statistics in the manner of a traditional index.<o:p></o:p></span></div></div></span><br /><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 10pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><em><strong>Note</strong>: You can compare the performance optimization be executing heavy volume queries before and after creating columnstore index. You might get 50% to 90% performance gain!</em></div> </div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-2011512110375750522012-08-21T19:00:00.000-07:002013-03-23T13:09:38.969-07:00<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-size: large;"><b style="mso-bidi-font-weight: normal;"><span style="line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">Introducing </span></span></b><span style="color: magenta; font-family: Consolas; line-height: 115%; mso-bidi-font-size: 9.5pt;">IIF</span><span style="color: grey; font-family: Consolas; line-height: 115%; mso-bidi-font-size: 9.5pt;">() </span><b style="mso-bidi-font-weight: normal;"><span style="font-size: 15pt; line-height: 115%; mso-bidi-font-size: 11.0pt;"><span style="font-family: Calibri;">To<span style="mso-spacerun: yes;"> </span>SQL Server Family<o:p></o:p></span></span></b></span></div><br /><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: magenta; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-size: 9.5pt;">IIF</span><span style="color: grey; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-size: 9.5pt;">()</span><span style="font-family: Calibri;"> is a brand new logical function introduced with SQL Server 2012 that allows you to perform </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">IF</span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">...</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">THEN</span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;">...</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">ELSE</span><span style="font-family: Calibri;"> conditional statements within a single function. Behavior of this function is similar to any other programming language IIF() function!<o:p></o:p></span></div><br /><div class="MsoNormal" style="margin: 0in 0in 10pt;"><br /></div><br /><div class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri;">In earlier versions of SQL Server, we have used </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">IF</span><span style="color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">...</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">ELSE</span><span style="font-family: Calibri;">and </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">CASE WHEN</span><span style="color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">...</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">THEN</span><span style="color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">...</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">ELSE</span><span style="color: grey; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">...</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">END </span><span style="font-family: Calibri;">to perform logical conditional operations. <o:p></o:p></span></div><br /><div class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: magenta; font-family: Consolas; font-size: 10.5pt; line-height: 115%; mso-bidi-font-size: 9.5pt;">IIF</span><span style="color: grey; font-family: Consolas; font-size: 10.5pt; line-height: 115%; mso-bidi-font-size: 9.5pt;">()</span><span style="font-family: Calibri;"> can be handy for writing conditional CASE statements in a single function. It evaluates the expression passed in the first parameter and returns either TRUE or FALSE. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas;">--Example1: Repalcement of simple IF...ELSE statement</span><span style="font-family: Consolas;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">DECLARE</span><span style="font-family: Consolas;"> <span style="color: teal;">@Grade</span><span style="color: blue;">CHAR</span><span style="color: grey;">(</span>1<span style="color: grey;">)</span> <span style="color: grey;">=</span> <span style="color: red;">'A'</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">SELECT</span><span style="font-family: Consolas;"> <span style="color: magenta;">IIF</span><span style="color: grey;">(</span><span style="color: teal;">@Grade</span> <span style="color: grey;">=</span> <span style="color: red;">'F'</span><span style="color: grey;">,</span> <span style="color: red;">'Failed'</span><span style="color: grey;">,</span> <span style="color: red;">'Passed'</span><span style="color: grey;">) <span style="color: blue;">AS </span><span style="color: teal;">Result</span></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">GO</span><br /><span style="color: blue; font-family: Consolas;"></span><br /><span style="font-family: Calibri;">Here is the output of above T-SQL code:</span><br /><span style="font-family: Calibri;"></span> </div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqWeHqIWDJpp7R8suAiubi1lXQz1RurfCp5m1skpZsKxxnaeV7yc-0hFnp_nTr3sjwgb1fuNF5c6uJrysiLcBGY82efwTojeMimS9PFG2_SpE4CSrMxEIbqF2Rh9qlgeN7DL2jbjA53Big/s1600/IIF.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="115" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqWeHqIWDJpp7R8suAiubi1lXQz1RurfCp5m1skpZsKxxnaeV7yc-0hFnp_nTr3sjwgb1fuNF5c6uJrysiLcBGY82efwTojeMimS9PFG2_SpE4CSrMxEIbqF2Rh9qlgeN7DL2jbjA53Big/s400/IIF.PNG" width="400" /></a></div><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div><div class="MsoNormal" style="line-height: 115%; margin: 0in 0in 10pt;"><span style="font-family: Calibri;"></span><br /><span style="font-family: Calibri;"></span><br /><span style="font-family: Calibri;"></span><br /><span style="font-family: Calibri;"></span><br /><span style="font-family: Calibri;"></span><br /><span style="font-family: Calibri;"></span><br /><br /><span style="font-family: Calibri;"></span><br /><span style="font-family: Calibri;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas;">--Example2: Nested IIF()</span><span style="font-family: Consolas;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">DECLARE</span><span style="font-family: Consolas;"> <span style="color: teal;">@Percent</span><span style="color: blue;">DECIMAL</span><span style="color: grey;">(</span>5<span style="color: grey;">,</span> 2<span style="color: grey;">)</span> <span style="color: grey;">=</span> <span style="color: red;">'50'</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">SELECT</span><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: magenta;">IIF</span><span style="color: grey;">(</span><span style="color: teal;">@Percent</span> <span style="color: grey;">></span> 80<span style="color: grey;">,</span> <span style="color: red;">'A'</span><span style="color: grey;">,</span> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: magenta;">IIF</span><span style="color: grey;">(</span><span style="color: teal;">@Percent</span> <span style="color: grey;">></span> 60<span style="color: grey;">,</span> <span style="color: red;">'B'</span><span style="color: grey;">,</span> <span style="color: red;">'C'</span><span style="color: grey;">))</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas;">GO</span><span style="color: grey; font-family: Consolas;">;</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div><div class="MsoNormal" style="line-height: 115%; margin: 0in 0in 10pt;"><span style="font-family: Calibri;">Here is the output of above T-SQL code:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;">----<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;">C<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;">(1 row(s) affected)</span><br /><span style="font-family: Consolas;"></span><br /><span style="font-family: Consolas;"></span><br /><span style="font-family: Consolas; font-size: 9pt;"></span><br /><span style="font-family: Consolas; font-size: 9pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; font-family: Consolas; font-size: small;">-- Example3: In this example, we will evaluate the marks obtained </span><br /><span style="font-size: small;"><span style="color: green; font-family: Consolas;">-- by Smith and Hari </span><span style="color: green; font-family: Consolas;">and identify who got higer marks between them.</span></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: small;"><span style="color: blue; font-family: Consolas;">DECLARE</span><span style="font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: teal;">@Smith_Marks</span> <span style="color: blue;">INT</span><span style="color: grey;">=</span> 72<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-size: small;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">,</span><span style="color: teal;">@Hari_Marks</span> <span style="color: blue;">INT</span> <span style="color: grey;">=</span> 86<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: small;"><span style="color: blue; font-family: Consolas;">SELECT</span><span style="font-family: Consolas;"> <span style="color: magenta;">IIF</span><span style="color: grey;">(</span><span style="color: teal;">@Smith_Marks</span> <span style="color: grey;">></span> <span style="color: teal;">@Hari_Marks</span></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-size: small;"><span style="mso-spacerun: yes;"> </span><span style="color: magenta;">,CONCAT</span><span style="color: grey;">(</span><span style="color: red;">'Smith got '</span><span style="color: grey;">,</span><span style="color: teal;">@Smith_Marks</span><span style="color: grey;">-</span><span style="color: teal;">@Hari_Marks</span><span style="color: grey;">,</span><span style="color: red;">' marks higher than Hari'</span><span style="color: grey;">)</span> <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-size: small;"><span style="mso-spacerun: yes;"> </span><span style="color: magenta;">,CONCAT</span><span style="color: grey;">(</span><span style="color: red;">'Hari got '</span> <span style="color: grey;">,</span><span style="color: teal;">@Hari_Marks</span><span style="color: grey;">-</span><span style="color: teal;">@Smith_Marks</span><span style="color: grey;">,</span><span style="color: red;">' marks higher than Smith'</span><span style="color: grey;">)</span><o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-size: small;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">)</span><o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: blue; font-family: Consolas; font-size: small;">GO</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;"><br /></div><div class="MsoNormal" style="line-height: 115%; margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;">Here is the output:</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas;"><span style="font-size: small;">---------------------------------------------<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; font-size: small;">Hari got 14 marks higher than Smith</span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: small;"></span><br /></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; font-size: small;">(1 row(s) affected)</span><br /><br /><br /><br /></div></span><br /><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </div></div></span><br /></div><br /><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><br /></div></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-68854152240238409292012-08-04T23:00:00.000-07:002013-03-23T13:09:38.978-07:00<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #660000; font-size: large;"><strong>SQL Server 2012 Analytical Functions: Lead and Lag</strong></span><br /><br /><span style="color: #0c343d;">SQL Server 2012 supports many T-SQL analytic functions which are listed below:</span><br /><ul style="text-align: left;"><li><span style="color: #0c343d;"><strong>LEAD</strong>: Accesses data from a subsequent row in the same result set without the use of a self-join.</span></li><li><span style="color: #0c343d;"><strong>LAG</strong>: Accesses data from a previous row in the same result set without the use of a self-join.</span></li><li><span style="color: #0c343d;"><strong>CUME_DIST</strong>: Calculates the cumulative distribution of a value in a group of values. In other words, CUME_DIST computes the relative position of a specified value in a group of values</span></li><li><span style="color: #0c343d;"><strong>FIRST_VALUE</strong>: Returns the first value in an ordered set of values.</span></li><li><span style="color: #0c343d;"><strong>LAST_VALUE</strong>: Returns the last value in an ordered set of values.</span></li><li><span style="color: #0c343d;"><strong>PERCENTILE_CONT</strong>: Calculates a percentile based on a continuous distribution of the column.</span></li><li><span style="color: #0c343d;"><strong>PERCENTILE_DISC</strong>: Computes a specific percentile for sorted values in an entire rowset or within distinct partitions of a rowset.</span></li><li><span style="color: #0c343d;"><strong>PERCENT_RANK</strong>: Calculates the relative rank of a row within a group of rows.</span></li></ul><div style="text-align: left;"><span style="color: #0c343d;">Analytic functions compute an aggregate value based on a group of rows. However, unlike aggregate functions, they can return multiple rows for each group. You can use analytic functions to compute moving averages, running totals, percentages or top-N results within a group.</span></div><div style="text-align: left;"></div><div style="text-align: left;"><span style="color: #0c343d;">In this article, we are going to focus only on <strong>Lead</strong> and <strong>Lag</strong> functions. </span></div><div style="text-align: left;"><span style="color: #0c343d;"><strong>Lead</strong> function accesses data from a subsequent row and <strong>Lag</strong> function accesses from previous row in the same result set without the use of a self-join.</span></div><div style="text-align: left;"></div><div style="text-align: left;"><span style="color: #0c343d;"><strong>Syntax</strong>:</span></div><div style="text-align: left;"><span style="color: #0c343d;">LEAD | Lag ( scalar_expression [ ,offset ] , [ default ] ) <br /> OVER ( [ partition_by_clause ] order_by_clause )</span></div><div style="text-align: left;"><span style="color: #0c343d;"><span class="parameter"><strong>scalar_expression </strong>is the</span> value to be returned based on the specified offset. <strong>Offset </strong>specify the number of rows forward/backward from the current row from which to obtain a value. <strong>Default </strong>is the value to return when <span class="parameter">scalar_expression</span> at <span class="parameter">offset</span> is NULL.</span></div><div style="text-align: left;"></div><div style="text-align: left;"><span style="color: #0c343d;">Now lets explorer Lead function with an example:</span></div><div style="text-align: left;"><span style="color: #0c343d;"><strong>Problem</strong>: Compare values between current year, previors year, and next year.</span></div><div style="text-align: left;"></div><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"></span></span></span><br /><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"></span></span></span><br /><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"></span></span></span><br /><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><div style="text-align: left;">---------------------</div><div style="text-align: left;">-- Prepare Test Data</div><div style="text-align: left;">---------------------</div></span></span></span><br /><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"></span></span></span><br /><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;">DECLARE <span style="color: teal;">@TestData</span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">TABLE </span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">(</span></span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Period</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">DATE</span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">INT</span></span></span></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">INSERT <span style="color: teal;">@TestData</span></span></span></span></div><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"></span></span></span><div style="text-align: left;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">SELECT <span style="color: red;">'2006-12-31' <span style="color: teal;">Period</span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> 1000 </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount <span style="color: blue;">UNION</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;">SELECT <span style="color: red;">'2007-12-31' <span style="color: teal;">Period</span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> 3000 </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount <span style="color: blue;">UNION</span></span></span></span></span></div></span></span></span><div style="text-align: left;">SELECT <span style="color: red;">'2008-12-31' <span style="color: teal;">Period</span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> 5000 </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount <span style="color: blue;">UNION</span></span></span></span></span></div></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;">SELECT <span style="color: red;">'2009-12-31' <span style="color: teal;">Period</span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> 4000 </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount <span style="color: blue;">UNION</span></span></span></span></span></div><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;">SELECT <span style="color: red;">'2010-12-31' <span style="color: teal;">Period</span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> 7000 </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount <span style="color: blue;">UNION</span></span></span></span></span></div><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;">SELECT <span style="color: red;">'2011-12-31' <span style="color: teal;">Period</span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> 6000 </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount <span style="color: blue;">UNION</span></span></span></span></span></div></span></span></span><div style="text-align: left;">SELECT <span style="color: red;">'2012-12-31' <span style="color: teal;">Period</span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> 8000 </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount</span></span></span></span></div></span><div style="text-align: left;"></div></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"></span></span></span> </div><div style="text-align: left;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">----------------------------------------------------------</span></span></span></div><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><div style="text-align: left;">-- Fetch current year, previous year, and next year data</div><div style="text-align: left;">----------------------------------------------------------</div></span></span></span><br /><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">SELECT <span style="color: teal;">Period</span></span></span></span><br /><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"></span></span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">AS</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">CurrentAmount</span></span></span></span></span><br /><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;"><div style="text-align: left;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">LAG</span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">(</span></span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount</span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> 1</span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> 0</span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">)</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">OVER </span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">(</span></span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">ORDER</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">BY</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Period</span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">)</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">AS</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">PreviousAmount</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span></span><br /><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><div style="text-align: left;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">LEAD</span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">(</span></span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Amount</span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> 1</span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">,</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> 0</span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">)</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">OVER </span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">(</span></span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">ORDER</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">BY</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">Period</span></span></span><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;"><span style="color: grey; font-family: Consolas; font-size: x-small;">)</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">AS</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;"><span style="color: teal; font-family: Consolas; font-size: x-small;">NextAmount</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span><div style="text-align: left;"><div style="text-align: left;">FROM <span style="color: teal;">@TestData</span></div></div></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"></div></span><div style="text-align: left;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></div><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"></span></span></span></span></span></span></span></span></span></span></div><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;"><div style="text-align: left;"><div style="text-align: left;"></div></div></div></span><div style="text-align: left;"><div style="text-align: left;"><div style="text-align: left;"></div></div></div></span><div style="text-align: left;"><div style="text-align: left;"><div style="text-align: left;"></div></div></div></span><div style="text-align: left;"><div style="text-align: left;"><div style="text-align: left;"></div></div><div style="text-align: left;"></div></div></span><div style="text-align: left;"><div style="text-align: left;"></div></div></span><div style="text-align: left;"><div style="text-align: left;"></div></div></span><div style="text-align: left;"><div style="text-align: left;"></div></div></span><div style="text-align: left;"><div style="text-align: left;"></div></div></span><div style="text-align: left;"><br /><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5i6xBmZEOz4VhQ-KLkPkpgjhFnMdga_CbhiIQspwekHdneGFcdqnVMn40e4J3P5UQU5yaDCB2GsnkUXJMpUAiG4MGY4HZY3oNGX-PO7KPRLDzlCWe-D9Y2WrjG5zOCjkch_Y27IqurqMW/s1600/Data.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="127" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5i6xBmZEOz4VhQ-KLkPkpgjhFnMdga_CbhiIQspwekHdneGFcdqnVMn40e4J3P5UQU5yaDCB2GsnkUXJMpUAiG4MGY4HZY3oNGX-PO7KPRLDzlCWe-D9Y2WrjG5zOCjkch_Y27IqurqMW/s400/Data.png" width="400" /></a></div><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"></span></span></span></div><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"></span></span></span><br /><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><div style="text-align: left;"></div></span><div style="text-align: left;"> </div><div style="text-align: left;"></div></span><div style="text-align: left;"> </div><div style="text-align: left;"> </div></span><br /><div style="text-align: left;"></div><div style="text-align: left;"></div></div></span><div style="text-align: left;"><div style="text-align: left;"></div></div></span><br /><div style="text-align: left;"><div style="text-align: left;"> </div><div style="text-align: left;"> </div><div style="text-align: left;"> </div></div></div></span><div style="text-align: left;"><div style="text-align: left;"><div style="text-align: left;"></div></div></div></span><br /><div style="text-align: left;"><div style="text-align: left;"><div style="text-align: left;"><span style="color: #0c343d;">Note that in the above we have set the default vaule 0 for Lead and Lag functions so we are getting zero (0) instead of NULL. Also we have set the offset to 1 for lead and lag function so we are getting only subsequent and previous values. Offset can be set as per requirement but in most of the cases we use 1.</span></div></div></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><span style="color: #0c343d;">For more information on Analytical Functions, please click</span> <a href="http://technet.microsoft.com/en-us/library/hh213234(v=SQL.110).aspx" target="_blank">here</a>.</div></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-22760712729872454672012-07-27T23:41:00.000-07:002013-03-23T13:09:38.989-07:00<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #262626; font-family: "Calibri","sans-serif"; font-size: 18pt; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><strong><span style="color: #0c343d;">CONCAT() IN SQL SERVER 2012</span></strong></span><br /><span style="color: #262626; font-family: "Calibri","sans-serif"; font-size: 18pt; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><span style="color: black; font-family: Times New Roman; font-size: small;"> </span></span><br /><div class="MsoNormal" style="margin: 0in 0in 0pt;"><b><span style="color: #262626;">SQL Server 2012</span></b><span style="color: #262626;"> introduces a new string function CONCAT() which allows you to concatenate up to 255 string or variable values in to one single string. It requires a minimum of two input values. Good thing about the function is that it takes care of implicitly converting the data values to a string by following the data type conversion rules of SQL Server 2012. This function would help eliminate the need of explicit data conversions when concatenating two values.<o:p></o:p></span></div><span style="color: black; font-family: Times New Roman;"> </span><br /><div class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="color: #262626;"><o:p> </o:p></span><b><span style="color: #262626;">Note:</span></b><span style="color: #262626;"> NULL values are implicitly converted to an empty string. If all the variables passed as parameters in CONCAT function are NULL, an empty string of type VARCHAR(1) is returned. <o:p></o:p></span></div><span style="color: black; font-family: Times New Roman;"> </span><br /><span style="color: black; font-family: Times New Roman;"> </span><span style="color: black; font-family: Times New Roman;"></span><br /><span style="color: black; font-family: Times New Roman;"><div class="MsoNormal" style="margin: 0in 0in 0pt;"><b><span style="color: #262626;"><span style="font-family: Calibri;">SYNTAX: <o:p></o:p></span></span></b></div><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"></span></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">CONCAT</span></span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"> </span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">String_Value1</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">String_Value2</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">String_Value3</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">[, String_ValueN]</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">)</span></span></span><br /><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"></span></span></span><span style="color: #262626;"><span style="font-family: Calibri;"><o:p></o:p></span></span><span style="color: green; font-family: Consolas;"><span style="color: green; font-family: Consolas;"><span style="color: green; font-family: Consolas;">-- Between 2 and 254 values can be passed.</span></span></span> </span><span style="color: black; font-family: Times New Roman;"><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><b><span style="color: #262626;"><span style="font-family: Calibri;">EXAMPLE:</span></span></b></div><span style="color: #262626;"><span style="font-family: Calibri;"><strong> </strong></span></span><br /><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">DECLARE</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@FirstName</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">NVARCHAR</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">10</span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">=</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">N'हरि'</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><br /><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@LastNameVARCHAR</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">10</span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">=</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'Sharma'</span></span></span><br /><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"></span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Cell</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VARCHAR</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">20</span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">=</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;">'+1 (425) XXX-YYYY'</span></span></span><br /><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"><span style="color: red; font-family: Consolas;"></span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Age</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">INT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">=</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> 30</span></span><br /><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Delimiter</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">VARCHAR</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">)</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">=</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">SPACE</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">(</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;">2</span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">)</span></span></span><br /><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"></span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;"><span style="color: blue; font-family: Consolas;">SELECT</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;"><span style="color: magenta; font-family: Consolas;">CONCAT</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">(</span></span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@FirstName</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Delimiter</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@LastName</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Delimiter</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Cell</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Delimiter</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">,</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;"><span style="color: teal; font-family: Consolas;">@Age</span></span></span><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;">)</span></span></span><br /><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"></span></span></span><b><span style="color: #262626;"><span style="font-family: Calibri;"><div class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"><span style="color: grey; font-family: Consolas;"></span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="color: #262626;"><span style="font-family: Calibri;">OUTPUT:</span></span></div><span style="font-family: Consolas;"><span style="font-family: Consolas;"> <br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ2GJiNSNXnOu261Ilte2Rx26lZAMLFx8l3KuoJ4jHyW7jwR08KvK_U_GxDwWVycjA2LUtEDwS58lqapT2mOsyU25CQdfWcOxelyervMcnjnb1UQi2ueSGJMs1OByHX154aoieMW6s6G8W/s1600/Concat.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ2GJiNSNXnOu261Ilte2Rx26lZAMLFx8l3KuoJ4jHyW7jwR08KvK_U_GxDwWVycjA2LUtEDwS58lqapT2mOsyU25CQdfWcOxelyervMcnjnb1UQi2ueSGJMs1OByHX154aoieMW6s6G8W/s1600/Concat.PNG" /></a></div><span style="color: black; font-family: Times New Roman;"> </span><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="color: #262626;"><span style="font-family: Calibri;">You might have observed that there’s no data conversion being performed in the above example.</span></span></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="color: #262626;"><span style="font-family: Calibri;">The data returned by CONCAT function depends on the type of valued passed. Below are some of the mapping input and output types:</span></span></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="color: #262626;"><span style="font-family: Calibri;"> <o:p></o:p></span></span></div><span style="color: black; font-family: Times New Roman;"> </span><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><span style="color: black; font-family: Times New Roman;"> </span><table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; margin: auto auto auto 99.6pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184;"><span style="font-family: Times New Roman;"> </span><tbody><tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"><span style="font-family: Times New Roman;"> </span><td style="background: rgb(221, 217, 195); border: 1pt solid windowtext; padding: 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><span style="font-family: Times New Roman;"> </span><br /><div style="text-align: left;"><b><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">Input Value / Type<o:p></o:p></span></span></span></b></div><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background: rgb(221, 217, 195); border-color: windowtext windowtext windowtext rgb(0, 0, 0); border-style: solid solid solid none; border-width: 1pt 1pt 1pt 0px; padding: 0in 5.4pt; width: 202.5pt;" valign="top" width="270"><span style="color: #0c343d; font-family: Times New Roman;"> </span><b><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">Output Value / Type<o:p></o:p></span></span></span></b><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span></tr><span style="color: #0c343d; font-family: Times New Roman;"> </span><tr style="mso-yfti-irow: 1;"><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; padding: 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">SQL-CLR (TYPES & UDT)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; padding: 0in 5.4pt; width: 202.5pt;" valign="top" width="270"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">NVARCHAR(MAX)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span></tr><span style="color: #0c343d; font-family: Times New Roman;"> </span><tr style="mso-yfti-irow: 2;"><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; padding: 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">NVARCHAR(MAX)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; padding: 0in 5.4pt; width: 202.5pt;" valign="top" width="270"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">NVARCHAR(MAX)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span></tr><span style="color: #0c343d; font-family: Times New Roman;"> </span><tr style="mso-yfti-irow: 3;"><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; padding: 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">NVARCHAR(<=4000)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; padding: 0in 5.4pt; width: 202.5pt;" valign="top" width="270"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">NVARCHAR(<=4000)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span></tr><span style="color: #0c343d; font-family: Times New Roman;"> </span><tr style="mso-yfti-irow: 4;"><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; padding: 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">VARBINARY(MAX)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; padding: 0in 5.4pt; width: 202.5pt;" valign="top" width="270"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">NVARCHAR(MAX)<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span></tr><span style="color: #0c343d; font-family: Times New Roman;"> </span><tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes;"><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; padding: 0in 5.4pt; width: 184.5pt;" valign="top" width="246"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">ALL OTHER INPUT TYPES<o:p></o:p></span></span></span><br /><span style="color: #0c343d; font-family: Times New Roman;"> </span></td><span style="color: #0c343d; font-family: Times New Roman;"> </span><td style="background-color: transparent; border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; padding: 0in 5.4pt; width: 202.5pt;" valign="top" width="270"><span style="color: #0c343d; font-family: Times New Roman;"> </span><span style="color: black; font-family: "Segoe UI","sans-serif"; font-size: 10pt;"><span style="color: #0c343d;"><span style="font-size: small;">VARCHAR(<=8000) *Unless one of the parameters is an NVARCHAR of any length and in that case, the output value would be in NVARCHAR(MAX)<o:p></o:p></span></span></span><br /><span style="font-family: Times New Roman;"> </span></td><span style="font-family: Times New Roman;"> </span></tr><span style="font-family: Times New Roman;"></span></tbody></table><span style="color: black; font-family: Times New Roman;"> </span><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div><span style="color: black; font-family: Times New Roman;"> </span><div class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span style="color: #cc0000;">NOTE</span>: CONCAT function only works with SQL Server 2012 and later versions.</span><span style="color: black; font-family: Times New Roman;"> </span></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"></div></span><div class="MsoNormal" style="margin: 0in 0in 0pt;"></div></span><div class="MsoNormal" style="margin: 0in 0in 0pt;"><br /></div></span><div class="MsoNormal" style="margin: 0in 0in 0pt;"></div><div class="MsoNormal" style="margin: 0in 0in 0pt;"></div></span><div class="MsoNormal" style="margin: 0in 0in 0pt;"></div></b><div class="MsoNormal" style="margin: 0in 0in 0pt;"></div></span><br /></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-711943613249791202011-12-10T20:07:00.000-08:002013-03-23T13:09:38.999-07:00Creating Degenerated dimension<div dir="ltr" style="text-align: left;" trbidi="on"><div style="border: currentColor;"><strong><span style="color: #274e13;">Degenerate Dimensions</span></strong></div><div style="border: currentColor;"><span style="font-size: x-small;"></span></div>In a data warehouse, a <strong>degenerate dimension</strong> is a dimension which is <u>derived from the fact table</u> and <u>doesn't have its own dimension table</u>. Degenerate dimensions are often used when a fact table's grain represents transactional level data and one wishes to maintain system specific identifiers such as order numbers, invoice numbers and the like without forcing their inclusion in their own dimension. The decision to use degenerate dimensions is often based on the desire to provide a direct reference back to a transactional system without the overhead of maintaining a separate dimension table.<br /><br />Once a cube is created, we can add degenerate dimension to the cube. <br /><span style="color: blue;"><u><strong>Below are the steps to create Degenerate Dimension:</strong></u></span><br /><br />1. Click on <em>Add Cube Dimension</em> icon in Dimension Usage tab as shown below. It will open <strong>Add Cube Dimension</strong> dialogue box. <br /><div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgemqe2yHl8KjUTC5g6CD_uaL9pSFcFuUsCnQV-UwKoI5sWPxBRwj8nHLm38Kjgk-4DmBQw634PgGvu4J2luLUtjViIa0JfowPvR_8SjW-bJzoh495vPtS17XjomTyS1pdLe3qFER4Br8iy/s1600/Pic1.png" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgemqe2yHl8KjUTC5g6CD_uaL9pSFcFuUsCnQV-UwKoI5sWPxBRwj8nHLm38Kjgk-4DmBQw634PgGvu4J2luLUtjViIa0JfowPvR_8SjW-bJzoh495vPtS17XjomTyS1pdLe3qFER4Br8iy/s320/Pic1.png" tt="true" /></a></div><div class="separator" style="clear: both; text-align: left;">2. Click on <strong>New dimension</strong>… button in <strong>Add Cube Dimension</strong> dialogue box. </div><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0bFWBLmfIOuaSE9cTbcBbA8yUfj6ZWyxzkHdkCSj2ue16GSCmdifqZmDi03rWyQ5iS-vJk_B9NWzetrcXkLSgFQwzkY0XTkP4tSifS0OkgKbAq-6D-RMdgCI9Fbx2CCnwErX7jJvmC6cY/s320/Pic1.png" tt="true" /></span><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />3. It will open <strong>Dimension Wizard</strong>. Click on <strong>Next</strong> to continue… <br />4. Select required <strong>data source view</strong> and click on <strong>Next</strong> to continue… <br /><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVGg_NTDOT_-zc78N3MKTTZkUGNzd03ML4VtAsm7YZ9l33aBVSnk9aEkHDb_EX4HoDTd_L_hpk1pbmcG32PrtLiJ98HnpmA2MmgNQgggngJIRaNhrJtVPjwYuVaagKxWNh1XDuZ4sDnyZP/s320/Pic1.png" tt="true" /></span><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />5. Select <strong>Standard dimension</strong> option and click on <strong>Next </strong>to continue… <br />6. Select <strong>Main Dimension</strong> table and <strong>Key columns</strong>. Click on <strong>Next</strong> to continue… <br /><div class="separator" style="clear: both; text-align: center;"><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwJ-hROW_hHF2xvhQwcyAEJKZZxHlYph1dRkgRWnJHxh11EFY3pj3klpCqkSkjG8jO-VM7s5n6ra1LFZNipdWfxv3Pu1ackYaDEvSQXTLBRPpuiliaAkCLsDthEHK1gRvj8eORb9BJGXHb/s320/Pic1.png" tt="true" /></span></div><div class="separator" style="clear: both; text-align: left;">7. Select <strong>Dimension Attributes</strong>. Click on <strong>Next</strong> to continue… </div><div class="separator" style="clear: both; text-align: center;"><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkqzkc7wb69HuYchV4TtAQX7F3RibgRsxj2Fzb99P2d-a2yz2lFEVQj4Y-8vPD2vwGdgDiAB_NuYPUA9L0rchg1Cx4TG6mwVFAhjyGl_xdxnNIB8zV-J4Ke-z67otzvsehoYLqx2PqVShS/s320/Pic1.png" tt="true" /></span></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><div align="left">8. Click on <strong>Next</strong> to continue… </div><div class="separator" style="clear: both; text-align: left;"><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJnOeU9vZkoc817mx-EALJO-AYv9KIPZhdGAMW1iLy9Ygs22CXtxQUEvS0pcUgZYlMqI5kH4CULaCpXmc3UxmAmFUKFo0DyWintEvCE_QUueSVfehwV0UXtHUi_-lMBB8ImgcWm3Awu9Cp/s320/Pic1.png" tt="true" /></span></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />9. Now we are at <strong>Completing the Wizard</strong>. Give proper dimension name click <strong>Finish</strong> to complete. <br /><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg44D5zFCSkLWoTCksMEUwrP_QBSdthv7ALkHq-AXFIPNdrV8IREHyf6M5wHj6QFLC4nhXo0MtekhaCEBBgkurgQLkC9903nv-i4XkeZzHfEbALyXbzNFcjR-nFQHBlch1euWXrERdJbAT/s320/Pic1.png" tt="true" /></span><br /> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />10. Newly created dimension is now available in Dimension Usage tab. At the intersection of <strong>Fact Sales</strong> measure group and the <strong>Sales Order Number</strong> dimension, click the ellipsis button (…) in the <strong>Item Description</strong> cell to review the fact relationship properties. <br /><br /><div class="separator" style="clear: both; text-align: center;"><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhagHYZMGsjqFo1SP8OP37n-iAaSTkc_-zPiD6WbQ-aTh6RBJLy1wwVrKijaseegRtFBTOQZJIPISChjajsGbnd8ihJR1Q4Zh7aEVAp4Jp8nU-_r1dd9cpPkbX2XfGKu0c7ZpLZ1Q-uis4e/s320/Pic1.png" tt="true" /></span></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />The Define Relationship dialog box opens. Notice that you cannot configure any of the properties. The Selected relationship type should be <strong>Fact</strong>.<br /><br />The following image shows the fact relationship properties in the Define Relationship dialog box<br /><span style="clear: left; cssfloat: left; float: left; font-size: small; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoSSnG3CRnGqpdGCbMoYwrUbDO_Hfl6Avsb6IXYivz_K8GxU7LlaHZL3Tz6uoCEXqHiu_NSvNLVjEyD8kS7XKLmOQIIFE6jtSpuMObIvQer_MMhfCvJb5d5QXu0LDJ0szFkGZSBqAs0Zjf/s320/Pic1.png" tt="true" /></span><br /><br /><br /><div class="separator" style="border: currentColor; clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfRo4c3nbLyVHdsd665gTPyulpDm-mBsSS9wQeZzLhGCo2Ndzv97KsV5gME-urjGwDXKdlq2UgTH_6VNkto1wF3Lpdsd6xpqs-HR2evx-3qNmm6NWJWOV1lBGzCh8bcGYDrqObqI_kDD0E/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfRo4c3nbLyVHdsd665gTPyulpDm-mBsSS9wQeZzLhGCo2Ndzv97KsV5gME-urjGwDXKdlq2UgTH_6VNkto1wF3Lpdsd6xpqs-HR2evx-3qNmm6NWJWOV1lBGzCh8bcGYDrqObqI_kDD0E/s320/Pic1.png" tt="true" /></a></div><div class="separator" style="border: currentColor; clear: both; text-align: center;"><br /></div></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com2tag:blogger.com,1999:blog-5098208425613902582.post-65929319997187625312011-11-01T22:23:00.000-07:002013-03-23T13:09:39.005-07:00Key Performance Indicators (KPIs) using Analysis Services<div dir="ltr" style="text-align: left;" trbidi="on">In business terminology, a KPI is a quantifiable measurement for gauging business success. In Analysis Services, a KPI is a collection of calculations that are associated with a measure group in a cube that are used to evaluate business success. Typically, these calculations are a combination of Multidimensional Expressions (MDX) expressions or calculated members. KPIs also have additional metadata that provides information about how client applications should display the results of the KPI's calculations <br /><br /><div></div><strong><span style="color: #073763;">Common KPI Terms: </span></strong><br /><ul><li><strong><span style="color: red;">Goal</span> -</strong> An MDX numeric expression or a calculation that returns the target value of the KPI. </li><li><strong><span style="color: red;">Value</span> -</strong> An MDX numeric expression that returns the actual value of the KPI. </li><li><strong><span style="color: red;">Status</span> -</strong> An MDX expression that represents the state of the KPI at a specified point in time. The status MDX expression should return a normalized value between -1 and 1. Values equal to or less than -1 will be interpreted as "bad" or "low." A value of zero (0) is interpreted as "acceptable" or "medium." Values equal to or greater than 1 will be interpreted as "good" or "high." </li><li><strong><span style="color: red;">Trend</span></strong> - An MDX expression that evaluates the value of the KPI over time. The trend can be any time-based criterion that is useful in a specific business context. The trend MDX expression enables a business user to determine whether the KPI is improving over time or degrading over time. </li><li><strong><span style="color: red;">Status indicator</span></strong> - A visual element that provides a quick indication of the status for a KPI. </li><li><strong><span style="color: red;">Trend indicator</span></strong> - A visual element that provides a quick indication of the trend for a KPI. </li><li><strong><span style="color: red;">Display folder</span></strong> - The folder in which the KPI will appear when a user is browsing the cube. </li><li><strong><span style="color: red;">Parent KPI</span></strong> - A reference to an existing KPI that uses the value of the child KPI as part of computation of the parent KPI. Sometimes, a single KPI will be a computation that consists of the values for other KPIs. </li><li><strong><span style="color: red;">Weight</span></strong> - An MDX numeric expression that assigns a relative importance to a KPI. If the KPI is assigned to a parent KPI, the weight is used to proportionally adjust the results of the child KPI value when calculating the value of the parent KPI. </li></ul><strong><span style="color: #073763;">Creating KPIs using Business Intelligence Development Studio (BIDS)</span></strong><br /><ol><li>Click on the <strong><em>KPIs</em></strong> tab </li><li>We shall first add a KPI named <strong><em>ProfitPercentage</em></strong> to the cube: </li><ul><li>Click on the <em>New KPI</em> button or right-click on the KPI Organizer window and select <em>New KPI</em>.</li><li>In the KPI Designer which opens up, type in the name of the KPI as <em>ProfitPercentage</em>.</li></ul><li>Add the measure to the <strong>Sales Fact</strong> measure group by selecting from the <strong>Associated measure group</strong> drop down.</li><li>Now let's add an expression to evaluate the value property of the KPI: </li><ul><li>Type the following expression in the Value Expression box. You could also drag the measures from the Metadata tab in the Calculation tools window. <br /><div><span style="color: #073763;">[Measures].[Profit]/[Measures].[Product Cost]</span></div><div>OR </div><div><span style="color: #073763;">([Measures].[Sales Amount]/[Measures].[Product Cost]-1</span> </div><div></div><div>We have built the expression above using the logic that ProfitPercentage is calculated as the difference in Sales and Cost, divided by the Cost.</div><div>Here [Measures].[Profit] is Calculated Member using below calculation:</div><div></div><div><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">CREATE MEMBER CURRENTCUBE</span>.[MEASURES].[Profit]</span></div><span style="font-family: "Courier New", Courier, monospace;"></span><br /><div><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">AS</span> <span style="color: #660000;">SUM</span></span></div><div><span style="font-family: "Courier New", Courier, monospace;">(</span></div><div><span style="font-family: "Courier New", Courier, monospace;">[Date].[Calendar Year - Qtr - Month].<span style="color: #660000;">currentmember</span>, </span></div><div><span style="font-family: "Courier New", Courier, monospace;">[Measures].[Sales Amount]-[Measures].[Product Cost]</span></div><div><span style="font-family: "Courier New", Courier, monospace;">), </span></div><div><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">FORMAT_STRING</span> = <span style="color: #990000;">"#,#"</span>, </span></div><div><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">VISIBLE</span> = 1;</span><span style="font-family: "Courier New", Courier, monospace;"></span></div></li></ul><li>Now, let us set the goal of the KPI to a constant. Enter 0.25 in the Goal Expression box, which means the goal expects 25% more in sales than the cost.</li><li>Next we are on to the all important status. Here we shall write an expression to compare the value with the goal: </li><ul><li>Before examining the actual expression let us take a look at a pseudo-expression:<br />CASE<br /> WHEN value/goal >= 0.9 THEN 1<br /> WHEN value/goal < 0.8 THEN -1 <br /> ELSE 0 <br />END <br /><br />Here, a ratio of .9 would be considered good in this instance. This means that if the value makes up at least 90% of the <em>goal</em> then it would be considered as successful, hence the <em>value</em> 1 to indicate it. If <em>value/goal</em> equals to less than 0.8 then the status will be considered as a failure (-1). And all those values do not fall into the above ranges will be considered neutral (0). <br /><br />Now, enter the following MDX expression into the <em><strong>Status expression</strong></em> box:<br /><span style="color: blue;">CASE <br /> WHEN</span> <span style="color: #660000;">KPIValue</span>(<span style="color: #660000;">"ProfitPercentage"</span>)/<span style="color: #660000;">KPIGoal</span>(<span style="color: #660000;">"ProfitPercentage"</span>)>=.9 <span style="color: blue;">THEN</span> 1<br /><span style="color: blue;"> WHEN</span> <span style="color: #660000;">KPIValue</span>(<span style="color: #660000;">"ProfitPercentage"</span>)/<span style="color: #660000;">KPIGoal</span>(<span style="color: #660000;">"ProfitPercentage"</span>)< .8 <span style="color: blue;">THEN</span> -1 <span style="color: blue;"><br /> ELSE</span> 0 <span style="color: blue;"><br />END</span> <br /><br />Being the realization of the previous "pseudo-expression", the above expression replaces <em>value</em> with <em>KPIValue("ProfitPercentage")</em> and <em>goal</em> with <em>KPIGoal("ProfitPercentage")</em>. The KPIValue function returns the value of the KPI's value property, while the KPIGoal function returns the value of the KPI's goal property. Both functions take the name of the KPI through a character string parameter. </li></ul><li>Select an appropriate image type from the <em><strong>Status indicator</strong></em> drop down to provide for the visuals of the KPI status.</li><li>The next property to be configured is the trend. Once again, let us first look at a "pseudo-expression": <br />CASE<br /> WHEN IsEmpty(x) THEN 0<br /> WHEN v - vX >= 0.25 THEN 1<br /> WHEN v - vX < -0.1 THEN -1 <br /> ELSE 0 <br />END <br /><br />Here, x is the current time period of the previous year. For instance if the current selected time period is 20-May-2008, x will be 20-May-2007. v is the value of the KPI, which by default would return the value for the current time period. vx is the value of the KPI for the same time period of the previous year. The expression first checks if x is empty, thereby resulting in 0 (or no change in trend). Then, it checks if the current period's value is an increase of at least 25%, thereby indicating 1 or a positive trend. If there's a decrease of more than 10% from last year it indicates a negative trend or -1. All other results will indicate no change in the trend (or 0). <br /><br />Enter the following MDX expression in the Trend expression textbox: <br /><span style="color: blue;">CASE <br />WHEN</span> <span style="color: #660000;">IsEmpty</span>(<span style="color: #660000;">ParallelPeriod</span>([Date].[Calendar Year - Qtr – Month].[Calendar Year], 1,[Date].[Calendar Year - Qtr – Month].<span style="color: #660000;">CurrentMember</span>)) <span style="color: blue;">THEN</span> 0 <br /><span style="color: blue;">WHEN</span> <span style="color: #660000;">KPIValue</span>(<span style="color: #660000;">"ProfitPercentage"</span>)-(<span style="color: #660000;">KPIValue</span><span style="color: #660000;">("ProfitPercentage"</span>), <span style="color: #660000;">ParallelPeriod</span>([Date].[Calendar Year - Qtr - Month].[Calendar Year],1,[Date].[Calendar Year - Qtr - Month].<span style="color: #660000;">CurrentMember</span>)) >= 0.25 <br /><span style="color: blue;">THEN</span> 1<br /><span style="color: blue;">WHEN</span> <span style="color: #660000;">KPIValue</span>(<span style="color: #660000;">"ProfitPercentage"</span>) - <span style="color: #660000;">KPIValue</span>(<span style="color: #660000;">"ProfitPercentage"</span>), <br /><span style="color: #660000;">ParallelPeriod</span>([Date].[Calendar Year - Qtr - Month].[Calendar <br />Year],1,[Date].[Calendar Year - Qtr - Month].<span style="color: #660000;">CurrentMember</span>)) < -0.1 <span style="color: blue;">THEN</span> -1 <br /><span style="color: blue;">ELSE</span> 0 <br /><span style="background-color: white; color: blue;">END</span> <br /><br />In the MDX expression above, x is replaced by ParallelPeriod([Date].[Calendar Year - Qtr - Month].[Calendar Year], 1,[Date].[Calendar Year - Qtr - Month].CurrentMember) ParallelPeriod is a function which returns a member from a prior period in the same relative position as a specified member. The variable v is replaced by KPIValue("ProfitPercentage") and vx is replaced by (KPIValue("ProfitPercentage"), ParallelPeriod([Date].[Calendar Year - Qtr - Month].[Calendar Year], 1,[Date].[Calendar Year - Qtr - Month].CurrentMember)). </li><li>Select an appropriate image type from the Trend indicator drop down to provide for the visual of the KPI trend. Here's a sample of what the KPI designer should look like:<br /><br /><div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhALeeX14Ak2eAvMt8wxamZWLhpQXTMew28lGI6CkreM6Yzt17JCP5wJRxt80Jxx0wVErFZ5KXVN-Z66MFQpC-TpnCOkuOQrpHKMgU9MZOpNE9mG8fsw8BHMWEQAAbYVbZAT2AaKURN21Db/s1600/kpi.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhALeeX14Ak2eAvMt8wxamZWLhpQXTMew28lGI6CkreM6Yzt17JCP5wJRxt80Jxx0wVErFZ5KXVN-Z66MFQpC-TpnCOkuOQrpHKMgU9MZOpNE9mG8fsw8BHMWEQAAbYVbZAT2AaKURN21Db/s320/kpi.png" tt="true" /></a></div></li><li><br /><div class="separator" style="clear: both; text-align: center;">The KPIs is done! Next, process the cube. You will be able to view the KPIs using the built-in KPI Browser under the KPIs tab in BIDS. You could also use Office 2007 Excel.</div><br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6TdzygThp9BWiGBXC02I7RHYdJT9bQ0TZZJVyaX_6ou6esDta7SnydYzi5XBGcXZPZIHlAG00xjsvXc9aai_1DwyNpm24NAYYeSfJ7Fjm_SeOqxqaDljE_aud4HklOa7ZUsD7o2WCY4U4/s1600/kpi.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6TdzygThp9BWiGBXC02I7RHYdJT9bQ0TZZJVyaX_6ou6esDta7SnydYzi5XBGcXZPZIHlAG00xjsvXc9aai_1DwyNpm24NAYYeSfJ7Fjm_SeOqxqaDljE_aud4HklOa7ZUsD7o2WCY4U4/s320/kpi.png" tt="true" /></a> <br /><br /><br /> </li></ol></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com1tag:blogger.com,1999:blog-5098208425613902582.post-60950122740201338402011-10-01T16:11:00.000-07:002013-03-23T13:09:39.013-07:00Sort Dimension Members in DESCending order<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;">Sometimes we need to display Date dimension members in descending order. For example, Client ask to show <strong>Calendar Year</strong> in DESC order.</div><div style="text-align: left;">But Analysis Services doesn't provide a way to sort dimension members in Descending order. SSAS provides only Ascending order.</div><div style="text-align: left;">However, we can achieve this sort functionality by using a simple <strong>trick</strong>. I will take an example to display Calendar Year member in DESC order. Below are the steps to achieve our goal:</div><div style="text-align: left;"><br /></div><div style="text-align: left;"><strong>Step1</strong>: Go to <strong>Data Source View </strong>(DSV) and right click on <em>Date</em> dimension in DSV diagram. Click on <em>New Named Calculation...</em> to create a new member.<br /></div><div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_FJ9ueODebHWFdUXePMUKcJNe1vF8xuB5SUJmNXwMahDS1hRxIdpmV08tAgNOnlvEXELU9wBejCkl5kuBhMwjGitptErkEze4AwVv_EKsMPnRtw3h-IuI9LiYlbyakLIujeGtEzp7awlZ/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" gu="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_FJ9ueODebHWFdUXePMUKcJNe1vF8xuB5SUJmNXwMahDS1hRxIdpmV08tAgNOnlvEXELU9wBejCkl5kuBhMwjGitptErkEze4AwVv_EKsMPnRtw3h-IuI9LiYlbyakLIujeGtEzp7awlZ/s320/1.png" /></a></div><div style="text-align: left;"><br /></div><div style="text-align: left;">Step2: Now enter <strong>CalendarYearSort</strong> in <em>Column name </em>and <strong><span style="font-family: Times, "Times New Roman", serif;">0-CalendarYear</span></strong> in <em>Expression</em> textbox. This additional column will be used to sort calendar year in descending order. Click OK to proceed. Here I considered that CalendarYear is existing column in the dimension.</div><br /><div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNaxR0H9G_9-YpQqDdEQJ230eG2cow7m5Jd9yQatMhhOd5bblCwAXjpUmWMVpc4tAP_PjefvOvOVVKQlFXn5iGY-M9iyui_axyBxL6p87ZKGqCM96DFCPXf30sT-eZY6H4En-7W1BglEqh/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" gu="true" height="233" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNaxR0H9G_9-YpQqDdEQJ230eG2cow7m5Jd9yQatMhhOd5bblCwAXjpUmWMVpc4tAP_PjefvOvOVVKQlFXn5iGY-M9iyui_axyBxL6p87ZKGqCM96DFCPXf30sT-eZY6H4En-7W1BglEqh/s320/1.png" width="320" /></a></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><br />Step3: Go to <em>Dimension Structure</em> of Date dimension and drag and drop new member "CalendarYearSort" in attributes list.</div><div style="text-align: left;"><br /></div><div style="text-align: left;">Step4: Click on <strong>Attributes Relationship</strong> tab. Right click on <strong>Calendar Year</strong> member and select <em>New Attribute Relationship...</em> It will open <strong>Create Attribute Relationship</strong> wizard.</div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixTj_loQ6LRK0EIFw3uXwANYraV6OcaCDomRfkE41Ck7n1S7d4SJMIHAB0Z0fRaLymseKb9L7iC6Uyt8DSMhUgOB3AAqQFN4U7tTq_qoCPQcDp3B-d223jxBGzNwDSoJV0iOU5v-jN8tYb/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" gu="true" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixTj_loQ6LRK0EIFw3uXwANYraV6OcaCDomRfkE41Ck7n1S7d4SJMIHAB0Z0fRaLymseKb9L7iC6Uyt8DSMhUgOB3AAqQFN4U7tTq_qoCPQcDp3B-d223jxBGzNwDSoJV0iOU5v-jN8tYb/s400/1.png" width="400" /></a></div><br /> </div><div style="text-align: left;"><br />Step5: In <strong>Create Attribute Relationship</strong>, select Related Attribute as <strong>Calendar Year Sort</strong> and Relationship type as <strong>Rigid</strong>. Click OK to proceed.</div><div style="text-align: left;"><br /></div><div style="text-align: left;">Step6: Again go back to <em>Dimension Structure</em> tab and click on <strong>Calendar Year</strong> attribute. Go to properties and set following things as shown below: </div><div style="text-align: left;"><strong>OrderBy</strong>: AttributeKey and <strong>OrderByAttribute</strong>: CalendarYearSort<br /></div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF29PYJtqVQKeAzvg0NypXc8FCInHPWe8PCa7QAadDuOg-zjHCCxkZmFzI__IFHFeqORPehpk9QSYUH-PWV70f_GPoJI3SMs2ujOEqHs3T7beKOrsXZgcmJsTwLPMfNkojf5LPIPE8Gt1g/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" gu="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF29PYJtqVQKeAzvg0NypXc8FCInHPWe8PCa7QAadDuOg-zjHCCxkZmFzI__IFHFeqORPehpk9QSYUH-PWV70f_GPoJI3SMs2ujOEqHs3T7beKOrsXZgcmJsTwLPMfNkojf5LPIPE8Gt1g/s320/1.png" /></a></div></div><div style="text-align: left;"><br /></div><div style="text-align: left;">Step7: Now Calendar Year is set in decending order. Just save and process the cube.</div><div style="text-align: left;"><br /></div><div style="text-align: left;">Note: Before processing the cube, you can set <strong>AttributeHierarchyVisible = FALSE</strong> because we should not show this attribute in cube and <strong>AttributeHierarchyEnabled</strong> = <strong>False </strong>to reduce cube space and increase the performance.</div></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com2tag:blogger.com,1999:blog-5098208425613902582.post-14942580911231528432011-09-03T20:40:00.000-07:002013-03-23T13:09:40.044-07:00Incremental Load in SSIS<div dir="ltr" style="text-align: left;" trbidi="on"><strong>Problem Description</strong>: Perform Incremental Load using SSIS package. There is one Source table with ID (may be Primary Key), CreatedDate and ModifiedDate along with other columns. The requirement is to load the destination table with new records and update the existing records (if any updated records are available). <br /><br /><div></div><strong>Soultion</strong>: <br />You can use <strong>Lookup Transformation</strong> where you compare source and destination data based on some id/code and get the new and updated records, and then use <strong>Conditoional Split </strong>to select the new and updated rows before loading the table.<br /><br />However, I don't recommend this approach, specially when destination table is very huge and volume of delta is very high.<br /><br />You can do it in simple steps:<br /><ol><li>Find the Maximum ID & Last ModifiedDate from destination and store in package variables.</li><li>Pull the new and updated records from source and load to a staging table using above variables.</li><li>Insert and Update the records using Execute SQL Task</li></ol>Here is the an step-by-step example to do this:<br /> <br />STEP1: <br />Create a new Package IncrementalLoad.dtsx and add following package variables:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9yZbE51yWWws2AW3vq91yaD-wBaN8aDWoX5JJr7zy-8NnCo2EPVrqIXH0_E8cQJXyehmB4ofk5_Vfd8GZgiyoI361gFRWIBAwRDSjRaniPA_n7x8hU-NebulCJpiI3bCkBUC8eLsCXvYQ/s1600/1.png" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="121" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9yZbE51yWWws2AW3vq91yaD-wBaN8aDWoX5JJr7zy-8NnCo2EPVrqIXH0_E8cQJXyehmB4ofk5_Vfd8GZgiyoI361gFRWIBAwRDSjRaniPA_n7x8hU-NebulCJpiI3bCkBUC8eLsCXvYQ/s320/1.png" width="320" /></a></div><br /><br /><br /><br /><br /><br /><br /><table border="1"><tbody><tr><td><strong>VariableName</strong></td><td><strong>Description</strong></td><td><strong>Examle</strong></td></tr><tr><td>DestinationConnStr</td><td>Connection string for <br />destination server/db</td><td>Data Source=(local);<br />Initial Catalog=TestHN;<br />Provider=SQLNCLI10.1;<br />Integrated Security=SSPI;<br />Auto Translate=False;</td></tr><tr><td>MaxID</td><td>Max ID from<br />destination table</td><td>100</td></tr><tr><td>MaxModifiedDate</td><td>Max Date from<br />destination table</td><td>2010:11:10 11:50:20.003</td></tr><tr><td>SourceConnStr</td><td>Connection string for <br />source server/db</td><td>Data Source=(local);<br />Initial Catalog=TestHN;<br />Provider=SQLNCLI10.1;<br />Integrated Security=SSPI;<br />Auto Translate=False;</td></tr></tbody></table><br /><div align="left"></div><br />STEP2:<br />Create Source, Destination, and staging tables using below code:<br /><br /><span style="color: #38761d;">-- Source Table (create in source DB)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">IF </span><span style="color: magenta;">OBJECT_ID</span>(<span style="color: red;">'dbo.TestSource'</span>,<span style="color: red;">'U'</span>) <span style="color: #999999;">IS NOT NULL</span></span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">DROP TABLE</span> dbo.TestSource</span><br /><span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">GO</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">CREATE Table </span>dbo.TestSource</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">(</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> [ID] [int] <span style="color: blue;">IDENTITY</span>(1,1)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[Code] [varchar](10)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[Description] [varchar](100)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[CreatedDate] [datetime] <span style="color: #999999;">NOT NULL</span> <span style="color: blue;">default</span> <span style="color: magenta;">GETDATE</span>()</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[ModifiedDate] [datetime] <span style="color: #999999;">NOT NULL</span> <span style="color: blue;">default</span> <span style="color: magenta;">GETDATE</span>()</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">)</span><br /><span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">GO</span><br /><br /><span style="color: #38761d;">-- Destination Table (create in destination DB)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">IF </span><span style="color: magenta;">OBJECT_ID</span>(<span style="color: red;">'dbo.TestDestination'</span>,<span style="color: red;">'U'</span>) <span style="color: #999999;">IS NOT NULL</span></span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">DROP TABLE</span> dbo.TestDestination</span><br /><span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">GO</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">CREATE Table </span>dbo.TestDestination</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">(</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> [ID] [int]</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[Code] [varchar](10)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[Description] [varchar](100)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[CreatedDate] [datetime] <span style="color: #999999;">NOT NULL</span> </span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[ModifiedDate] [datetime] <span style="color: #999999;">NOT NULL</span></span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">)</span><br /><span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">GO</span><br /><br /><span style="color: #38761d;">-- Staging Table (create in destination DB)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">IF </span><span style="color: magenta;">OBJECT_ID</span>(<span style="color: red;">'dbo.TestDestinationSTG'</span>,<span style="color: red;">'U'</span>) <span style="color: #999999;">IS NOT NULL</span></span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">DROP TABLE</span> dbo.TestDestinationSTG</span><br /><span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">GO</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="color: blue;">CREATE Table </span>dbo.TestDestinationSTG</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">(</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> [ID] [int]</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[Code] [varchar](10)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[Description] [varchar](100)</span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[CreatedDate] [datetime] <span style="color: #999999;">NOT NULL</span></span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> ,[ModifiedDate] [datetime] <span style="color: #999999;">NOT NULL</span></span><br /><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">)</span><br /><span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">GO</span><br /><br />STEP3: <br />Create two OLE DB Connection Manager, one for Source Server and another for Destination Server.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT0VrD7QZ4TLW-bspTNiKakM9WiUAQ5Fp0vX9nScBkXT79OJjIWZnNbSTegNKGjmSPNxbRyacKUUbxkZSiQ7APscH6xViCjDac9trmOiny-OXJV1ycv3G-lunjDOyy0rp9TtD4q1WQMdQf/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT0VrD7QZ4TLW-bspTNiKakM9WiUAQ5Fp0vX9nScBkXT79OJjIWZnNbSTegNKGjmSPNxbRyacKUUbxkZSiQ7APscH6xViCjDac9trmOiny-OXJV1ycv3G-lunjDOyy0rp9TtD4q1WQMdQf/s1600/1.png" /></a></div>In the connection manager properties, set the expression <strong>ConnectionString</strong> with respective variables as shown below:<br /><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7fchK6iimP7SQBUqVNPT9wMB_zjXkhGycUPNAyN64sxq5HNuVuqZd00ZuSN4mWeLtWnvW3T_xI9d5Awo76LdL_BaFPusc3MV9YYhGHkl80t0vL080R4N5aUGtGqlFgTfJHiSWJ0rOIV4v/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="177" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7fchK6iimP7SQBUqVNPT9wMB_zjXkhGycUPNAyN64sxq5HNuVuqZd00ZuSN4mWeLtWnvW3T_xI9d5Awo76LdL_BaFPusc3MV9YYhGHkl80t0vL080R4N5aUGtGqlFgTfJHiSWJ0rOIV4v/s320/1.png" width="320" /></a></div><br />STEP4:<br />Drag and drop Execute SQL Task and name it -<br /><strong>Execute SQL Task - Get Max ID and Last ModifiedDate</strong>.<br />Double click on EST and set following properties:<br />ResultSet = <strong>Single row</strong><br />Connection = <strong>Destination Server</strong><br />SQLStatement =<br /><span style="color: blue; font-family: "Courier New", Courier, monospace;">SELECT</span><br /><span style="font-family: "Courier New", Courier, monospace;"> <span style="color: magenta;">ISNULL</span>(<span style="color: magenta;">MAX</span>(ID) ,0) MaxID,</span><br /><span style="font-family: "Courier New", Courier, monospace;"> <span style="color: magenta;">ISNULL</span>(<span style="color: magenta;">MAX</span>(ModifiedDate),<span style="color: red;">'2000-01-01'</span>) MaxModifiedDate</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">FROM</span> TestDestination (<span style="color: blue;">NOLOCK</span>)</span><br /><br />Drag and drop another Execute SQL Task to Truncate staging table. Rename the task - <strong>Execute SQL Task - Truncate staging Table </strong>and set following properties:<br />ResultSet = <strong>None</strong><br />Connection = <strong>Destination Server</strong><br />SQLStatement = <span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">Truncate Table </span>dbo.TestDestinationStg</span><br /><br /> <br />Drag and drop Data Flow Task and name it <strong>Data Flow Task - Pull New and Updated rows</strong>. <br />Double click on DFT or click on Data Flow tab. <br />Now drag and drop OLE DB Source and select <strong>Source Server</strong> in <em>OLE DB connection manager</em>, select <strong>SQL command</strong> in <em>Data access mode</em>, and write following T-SQL code in SQL command text: <br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">SELECT </span>[ID],[Code],[Description],</span> <br /><span style="font-family: "Courier New", Courier, monospace;">[CreatedDate],[ModifiedDate]</span> <br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">FROM</span> TestSource</span> <br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">WHERE</span> [ID] > ? OR [ModifiedDate] >= ?</span> <br /> <br />Click on Columns to generate metadata and set <strong>Parameters</strong> for above query: <br /> <br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyy2cvN8Ur9wiiLLuYUtt-NVLNKHs0NETPf4vcWeiMdJ6lduhJEj-vBqHU4WSWXxu58CSqhucv1qYefN_Jmiq7aq3b_RJCSM5nAwqs3T-FFueQjQXAefKoMS-gSOcfTzXNaX14Ao_0DFah/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="173" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyy2cvN8Ur9wiiLLuYUtt-NVLNKHs0NETPf4vcWeiMdJ6lduhJEj-vBqHU4WSWXxu58CSqhucv1qYefN_Jmiq7aq3b_RJCSM5nAwqs3T-FFueQjQXAefKoMS-gSOcfTzXNaX14Ao_0DFah/s320/1.png" width="320" /></a></div><br />Now drag and drop OLE DB Destination task and select <strong>Destination Server</strong> in <em>OLE DB Connection manager</em>, <strong>Table or view - fast load </strong>in <em>Data access mode</em>, and <strong>dbo.TestDestinationSTG</strong> in <em>Name of the table or view</em>.<br />Now click on Mapping to map the metadat with source columns.<br /><br />Drag and drop one more Execute SQL Task and rename it to <strong>Execute SQL Task - Insert and Updated new rows </strong>and set following properties:<br />ResultSet = <strong>None</strong><br />Connection = <strong>Destination Server</strong><br />SQLStatement =<br /><span style="color: #38761d; font-family: "Courier New", Courier, monospace;">-- INSERT New Records</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">INSERT INTO </span>TestDestination</span><br /><span style="font-family: "Courier New", Courier, monospace;">([ID],[Code],[Description],</span><br /><span style="font-family: "Courier New", Courier, monospace;">[CreatedDate],[ModifiedDate])</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">SELECT </span></span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;"> </span>[ID],[Code],[Description],</span><br /><span style="font-family: "Courier New", Courier, monospace;"> [CreatedDate],[ModifiedDate]</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">FROM</span> TestDestinationStg </span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">WHERE</span> ID > ?</span><br /><span style="font-family: "Courier New", Courier, monospace;"><br /></span><br /><span style="color: #38761d; font-family: "Courier New", Courier, monospace;">--UPDATE modified records</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">UPDATE</span> D </span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">SET</span> D.[ID] = S.[ID]</span><br /><span style="font-family: "Courier New", Courier, monospace;">,D.[Code] = S.[Code]</span><br /><span style="font-family: "Courier New", Courier, monospace;">,D.[Description] = S.[Description]</span><br /><span style="font-family: "Courier New", Courier, monospace;">,D.[CreatedDate] = S.[CreatedDate]</span><br /><span style="font-family: "Courier New", Courier, monospace;">,D.[ModifiedDate] = S.[ModifiedDate]</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">FROM</span> TestDestination D</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: #999999;">JOIN</span> TestDestinationStg S</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;"> ON</span> S.ID = D.ID </span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">WHERE</span> </span><br /><span style="font-family: "Courier New", Courier, monospace;"> S.ID <= ? AND </span><br /><span style="font-family: "Courier New", Courier, monospace;"> S.ModifiedDate > D.ModifiedDate</span><br /><br />Click on Parameter Mapping and set the parameters as shown below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGj5IIrHynlnw54wvyY49wL2HiPWoXDfunrHvt3ytpuiN6O7mUl71sGCVbDYKxg1zSCLfBAOm3vGSu-qoaklRsD8acUEPxR6H4h_l66UIBHqRxcFOZeP_g13eyIldVheAjhdR1HcbQelOv/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="51" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGj5IIrHynlnw54wvyY49wL2HiPWoXDfunrHvt3ytpuiN6O7mUl71sGCVbDYKxg1zSCLfBAOm3vGSu-qoaklRsD8acUEPxR6H4h_l66UIBHqRxcFOZeP_g13eyIldVheAjhdR1HcbQelOv/s320/1.png" width="320" /></a></div><br />Finally package will look like below snapshot:<br /> <br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_HN03_Wk9vsdMEjmpRp6neLUE5wzzX0-_68gfAp1NyTTI9XKRoFGE2QCDdpCPyGPp7EF4rj1vDY7HkQteMYO36kkB8hA2C5dakK3pFXHfa6ASSJfpwkUxXa208lra636ZaoBmEkSnvNJt/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="229" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_HN03_Wk9vsdMEjmpRp6neLUE5wzzX0-_68gfAp1NyTTI9XKRoFGE2QCDdpCPyGPp7EF4rj1vDY7HkQteMYO36kkB8hA2C5dakK3pFXHfa6ASSJfpwkUxXa208lra636ZaoBmEkSnvNJt/s320/1.png" width="320" /></a></div><br />STEP5: <br />We are done with package development. Its time to test the package. I will test this package in three steps:<br />1. Insert few dummy records in Source table while keeping Destination table empty.<br /><span style="color: #38761d; font-family: "Courier New", Courier, monospace;">--CASE 1: First Time Execution</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">INSERT INTO </span>dbo.TestSource ([Code],[Description])</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">VALUES</span> (<span style="color: red;">'AAA'</span>,<span style="color: red;">'American Automobile Association'</span>)</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">WAITFOR DELAY </span><span style="color: red;">'00:00:01.100'</span> <span style="color: #38761d;">-- delay between two rows</span></span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">INSERT INTO </span>dbo.TestSource ([Code],[Description])</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">VALUES</span> (<span style="color: red;">'ABC'</span>,<span style="color: red;">'Associated Builders & Contractors'</span>)</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">WAITFOR DELAY </span><span style="color: red;">'00:00:01.150'</span></span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">INSERT INTO</span> dbo.TestSource ([Code],[Description])</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">VALUES</span> (<span style="color: red;">'RR'</span>,<span style="color: red;">'Road Runner'</span>)</span><br /><span style="color: blue; font-family: "Courier New", Courier, monospace;">GO</span><br /><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcA-VBMzeKpuN7trYXG4WKSjZDPBwYyjxEMBXoIADbH-qlrAznt4UprPBFrZjh14Wi3ZGl1UTtSBu55s_IZh4XbDaVf16RX9miLxl9dX7Ejx9ygJ-0SIs4xT6XXkilo8BgWrWKPtY2Pgt9/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="82" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcA-VBMzeKpuN7trYXG4WKSjZDPBwYyjxEMBXoIADbH-qlrAznt4UprPBFrZjh14Wi3ZGl1UTtSBu55s_IZh4XbDaVf16RX9miLxl9dX7Ejx9ygJ-0SIs4xT6XXkilo8BgWrWKPtY2Pgt9/s320/1.png" width="320" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div>Now execute the package and check the destination data. You can add <strong>Data viewers</strong> in Data Flow to see the result at run time as shown below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOhyU1TZlVUMNAvo0BwfBgCmZcIm4ecIyxF7dPpxj0vsnxjvl8cef5MYtEVHnyd7cojTeAkN_Blccpt4RkZo6JA3xTG9ywRmc6-SgXMzxdIdiYbaWq6byjYsliKnzedWorXthlyhtrd3yD/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="126" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOhyU1TZlVUMNAvo0BwfBgCmZcIm4ecIyxF7dPpxj0vsnxjvl8cef5MYtEVHnyd7cojTeAkN_Blccpt4RkZo6JA3xTG9ywRmc6-SgXMzxdIdiYbaWq6byjYsliKnzedWorXthlyhtrd3yD/s320/2.png" width="320" /></a></div><br />2. Insert few more records in Source table to check whether new records are inserted into Destination table.<br /><span style="color: #38761d; font-family: "Courier New", Courier, monospace;">--CASE 2: Only New Records</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">INSERT INTO</span> dbo.TestSource ([Code],[Description])</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">VALUES</span> (<span style="color: red;">'TSL'</span>,<span style="color: red;">'Trina Solar Limited'</span>)</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">WAITFOR DELAY</span> <span style="color: red;">'00:00:01' </span><span style="color: #38761d;">-- delay between two rows</span></span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">INSERT INTO </span>dbo.TestSource ([Code],[Description])</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">VALUES</span> ('FSLR','First Solar, Inc.')</span><br /><br />Now execute the package and check for new records:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbedbZHld3cNLiWeqrgpDVuZKvYP3KPBgh-2uOWq9O2TxK0Qm9_q2FWXvoR9rxre5h5S7JfVb23yFDiEbiMuAcELTSXRh6uxScZ2DBpJM_BwzeLvwG7mhqFivtelcDZrT3nwHb8eR7VnJN/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="120" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbedbZHld3cNLiWeqrgpDVuZKvYP3KPBgh-2uOWq9O2TxK0Qm9_q2FWXvoR9rxre5h5S7JfVb23yFDiEbiMuAcELTSXRh6uxScZ2DBpJM_BwzeLvwG7mhqFivtelcDZrT3nwHb8eR7VnJN/s320/3.png" width="320" /></a></div><br />3. Insert few more records and update few existing records in Source table and check whether both table are in sync.<br /><span style="color: #38761d; font-family: "Courier New", Courier, monospace;">--CASE 3 -- New & Updated Records</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">INSERT INTO</span> dbo.TestSource ([Code],[Description])</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">VALUES</span> (<span style="color: red;">'LDK'</span>,<span style="color: red;">'LDK Solar Co., Ltd'</span>)</span><br /><span style="font-family: "Courier New", Courier, monospace;"><br /></span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">UPDATE</span> dbo.TestSource </span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">SET</span> [Description] = <span style="color: red;">'Associated Builders and Contractors'</span>,</span><br /><span style="font-family: "Courier New", Courier, monospace;">ModifiedDate = <span style="color: magenta;">GETDATE</span>()</span><br /><span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;">WHERE</span> [Code] = <span style="color: red;">'ABC'</span></span><br /><br />Finaly check source and destination tables for match. Since I have both Source & Destination tables in one server, I can use <span style="color: blue;">EXCEPT</span> command (for this example) which retunrs no records i.e. both the tables are in sync.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4TZzCuHE8flp5RcLgUePpIwqrtNLvHSJLfTFsF5FTukN2KcqWOV2F_KrM2t3LleClIZd8PmCrhuEex91ILTbcgcCc0DCYa_JoJ4JB5BOwEOtbxUUkITeNdfpdjljrcZuH0vFX83H4FJOd/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="157" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4TZzCuHE8flp5RcLgUePpIwqrtNLvHSJLfTFsF5FTukN2KcqWOV2F_KrM2t3LleClIZd8PmCrhuEex91ILTbcgcCc0DCYa_JoJ4JB5BOwEOtbxUUkITeNdfpdjljrcZuH0vFX83H4FJOd/s320/4.png" width="320" /></a></div><br /><br />Cheers!!!</div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com5tag:blogger.com,1999:blog-5098208425613902582.post-29105440613954245142011-08-01T16:18:00.000-07:002013-03-23T13:09:40.141-07:00Pulling SharePoint List using SSIS 2008<div dir="ltr" style="text-align: left;" trbidi="on">Do you want to pull SharePoint List data into SQL database using SSIS? If your answer is Yes then you can go for SharePoint List Source. You can download the setup from Microsoft SQL Server Community Sample: Integration Services: here is the link: <a href="http://sqlsrvintegrationsrv.codeplex.com/releases/view/17652"><strong>SharePointListAdaptersSetup</strong></a><br /><br />This component has two controls - <u>SharePoint List Source</u> and <u>SharePoint List Destination</u>. The Specific Features of the included SSIS Components are:<br /><br /><strong>SharePoint Source Component</strong><br /><ul><li>Auto-detects all of the public fields from a SharePoint List or view of the list.</li><li>Supports removal of fields from the output flow, which optimizes the query against SharePoint for increased performance.</li><li>Supports restricting SharePoint data by a custom CAML query, which can be provided through a variable expression for fine tuned filtering over large lists.</li><li>Provides a tuning feature for the # of rows to return at a time. Often with SharePoint, large lists need to be brought over in smaller batches than wide (many field) lists, or else the Webservice will die.</li></ul><br /><div><strong>SharePoint Destination Component</strong></div><br /><ul><li>Auto-detects all of the editable fields from a SharePoint List</li><li>Only fields bound to columns from the input flow will be ‘updated’, for performance.</li><li>Supports deleting rows by ID</li></ul><br /><div><strong>System Requirements</strong></div><ul><li>.Net 3.5 Framework </li><li>SQL Server Integration Services 2008</li></ul><br /><div><strong> How to Use</strong></div><ul><li>Download the sample from <strong><a href="http://sqlsrvintegrationsrv.codeplex.com/releases/view/17652">SharePointListAdaptersSetup</a></strong></li><li>Run <strong>SharePointListAdaptersSetup.msi</strong> to install the SSIS component. This installer places pre-built binaries into the Global Assembly Cache (GAC) and into the C:\Program Files\Microsoft SQL Server\100\DTS\PipelineComponents directory (if present).</li><li>A good way to explore the sample is to try using it, understand its behavior, and then begin reviewing the source code for the component. If you do not see the SharePoint adapters in your toolbox automatically, then follow these instructions:</li><ul><li>Open <em>Business Intelligence Development Studio</em>, open a package, and then click <strong>Choose Toolbox Items</strong> on the <strong>Tools </strong>menu.</li><li>In the <strong>Choose Toolbox Items</strong> dialog box, click the <strong>SSIS Data Flow Items</strong> tab, and then check <strong>SharePoint Destination</strong> and <strong>SharePoint Source</strong>.</li><li>Click Ok.</li></ul><li>The SharePoint source and destination components should now appear in the toolbox for the data flow task. You can add the source and destination components to the data flow of the package.</li></ul></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com1tag:blogger.com,1999:blog-5098208425613902582.post-26545849024300739092011-07-05T21:02:00.000-07:002013-03-23T13:09:40.235-07:00Table Partition<div dir="ltr" style="text-align: left;" trbidi="on"><strong><span style="color: #274e13;">Table partitioning</span></strong> is a data organization scheme in which table data is divided across multiple data partitions or ranges according to values in a table column.<br /><br /><strong><span style="color: #274e13;">Benefits of table partitioning</span></strong><br /><br />There are numerous benefits of table partitioning: <br /><ul><li>To improve the scalability and manageability of large tables and tables in Database and Data Warehouse</li><li>Database and Data Warehouse that would benefit from easier roll-in and roll-out of table data </li><li>Furthermore, if a large table exists on a system with multiple CPUs, partitioning the table can lead to better performance through parallel operations.</li><li>A table with varying access patterns might be a concern for performance and availability when different sets of rows within the table have different usage patterns.</li></ul> The steps for creating a partitioned table include the following: <br /><ol><li>Create a partition function to specify how a table or index that uses the function can be partitioned.</li><li>Create a partition scheme to specify the placement of the partitions of a partition function on filegroups.</li><li>Create a table or index using the partition scheme. </li></ol> <br />Below are the steps to creation Horizontal Table Partition <br /><br /><span style="color: #274e13;">-- Create the partition function</span><br /><br /><span style="color: blue;">CREATE PARTITION FUNCTION</span> PartitionFunctionMonthly (<span style="color: blue;">int</span>)<br /><span style="color: blue;">AS RANGE RIGHT </span><br /><span style="color: blue;">FOR VALUES </span>(20100101, 20100201, 20100301)<br /><span style="color: blue;">GO</span><br /><br /><div></div><span style="color: #274e13;">-- Add the partition scheme</span><br /><span style="color: blue;">CREATE PARTITION SCHEME</span> PartitionSchemaMonthly<br /><span style="color: blue;">AS PARTITION</span> PartitionFunctionMonthly<br /><span style="color: #666666;">ALL</span> <span style="color: blue;">TO </span>( [PRIMARY] )<br /><span style="color: blue;">GO</span><br /><br /><div></div> <span style="color: #274e13;">-- Create a simple table</span><br /><span style="color: blue;">CREATE TABLE</span> PartitionTable (<br /> DateKey <span style="color: blue;">int</span> <span style="color: #666666;">NOT NULL</span>, <br /> CustomerKey <span style="color: blue;">int</span> <span style="color: #666666;">NOT NULL</span>, <br /> SalesAmt <span style="color: blue;">money</span>,<br /><span style="color: blue;">CONSTRAINT </span>PKPartitionTable <span style="color: blue;">PRIMARY KEY NONCLUSTERED</span><br /> (DateKey, CustomerKey)<br />)<br /><span style="color: blue;">ON</span> PartitionSchemaMonthly(DateKey) <br /><span style="color: blue;">GO</span><br /><br /><div></div><span style="color: #274e13;">------------------------------------</span><br /><span style="color: #274e13;">-- Unit Testing of Partitions</span><br /><span style="color: #274e13;">------------------------------------</span><br /><span style="color: #274e13;">-- Add some rows</span><br /><span style="color: blue;">INSERT INTO</span> PartitionTable (DateKey, CustomerKey, SalesAmt)<br /><span style="color: blue;">SELECT</span> 20091201, 1, 5000 <span style="color: blue;">UNION</span> <span style="color: #666666;">ALL</span><br /><span style="color: blue;">SELECT</span> 20100101, 2, 3000 <span style="color: blue;">UNION</span> <span style="color: #666666;">ALL</span><br /><span style="color: blue;">SELECT</span> 20100215, 7, 6000 <span style="color: blue;">UNION</span> <span style="color: #666666;">ALL</span><br /><span style="color: blue;">SELECT</span> 20100331, 5, 3000 <span style="color: blue;">UNION</span> <span style="color: #666666;">ALL</span><br /><span style="color: blue;">SELECT</span> 20100415, 8, 6000 <br /><span style="color: blue;">GO</span><br /><br /><div></div><span style="color: #274e13;">-- A query accesses the entire table, exactly as you'd expect.</span><br /><span style="color: blue;">SELECT <span style="color: black;">*</span> FROM</span> PartitionTable<br /><span style="color: blue;">GO</span><br /><br /><div></div><span style="color: #274e13;">--Query partition contents</span><br /><span style="color: blue;">SELECT</span> <br />$partition.PartitionFunctionMonthly(DateKey) <span style="color: blue;">AS</span> [Partition#],<br /><span style="color: magenta;">COUNT</span>(*) <span style="color: blue;">AS</span> RowCount, <br /><span style="color: magenta;">Min</span>(DateKey) <span style="color: blue;">AS</span> MinDate, <br /><span style="color: magenta;">Max</span>(DateKey) <span style="color: blue;">AS</span> MaxDate<br /><span style="color: blue;">FROM</span> PartitionTable <br /><span style="color: blue;">GROUP BY</span> $partition.PartitionFunctionMonthly(DateKey)<br /><span style="color: blue;">ORDER BY</span> [Partition#]<br /><span style="color: blue;">GO</span></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com5tag:blogger.com,1999:blog-5098208425613902582.post-36714900730404436042011-06-04T20:40:00.000-07:002013-03-23T13:09:40.329-07:00Moving Database Files From One Drive to Another<div dir="ltr" style="text-align: left;" trbidi="on">In practice, database files grows everyday. Sometimes it occupy the complete disk and we may end up in unsufficeint mamroy - leading to unexpected results.<br /><br />In this blog, I'll explain how to transfer database files from one drive to another. To explain, I'll create a test database <strong>TestDB</strong>. Here is the command:<br /><br /><span style="color: blue;">USE</span> [master]<br /><span style="color: blue;">GO</span><br /><br /><span style="color: blue;">IF</span> <span style="color: magenta;">DB_ID</span>(<span style="color: red;">N'TestDB'</span>) <span style="color: #666666;">IS NULL</span><br /><span style="color: blue;">BEGIN</span><br /><span style="color: blue;">CREATE DATABASE</span> [TestDB] <span style="color: blue;">ON PRIMARY</span> <br />(<br /> NAME = <span style="color: red;">N'TestDB'</span><br /> ,<span style="color: blue;">FILENAME</span> = <span style="color: red;">N'C:\MSSQL\Data\TestDB.mdf'</span><br /> ,SIZE = 3MB<br /> ,MAXSIZE = 2048GB<br /> ,FILEGROWTH = 1024KB<br />)<br /><span style="color: magenta;">LOG</span> <span style="color: blue;">ON</span> <br />(<br /> NAME = <span style="color: red;">N'TestDB_log'</span><br /> ,<span style="color: blue;">FILENAME</span> = <span style="color: red;">N'C:\MSSQL\Data\TestDB.ldf'</span><br /> ,SIZE = 3MB<br /> ,MAXSIZE = 2048GB<br /> ,FILEGROWTH = 10%<br />)<br /><span style="color: blue;">END</span><br /><span style="color: blue;">GO</span><br /><br /><span style="color: black;">Now check existing files location:</span><br /><br /><span style="color: blue;">USE </span>TestDB<br /><span style="color: blue;">GO</span><br /><span style="color: blue;">SELECT</span> name, physical_name, state_desc <br /><span style="color: blue;">FROM</span> TestDB.<span style="color: #38761d;">sys.master_files </span><br /><span style="color: blue;">WHERE</span> database_id = <span style="color: magenta;">DB_ID</span>(<span style="color: red;">N'TestDB'</span>)<br /> <br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivecA7n5vSSmU8zGcsV3UHUC6c-isT4fLAmMDCbJ_JkVqdyKmLbqyohMlGzL4XCkotwuic2z1jqt2EU3JcJhOG5vDEh4tbF40P7K49r5tCFs7EFyUIvTamF5Al27KKirouhKXa1vilnGyY/s1600/1.png" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" gu="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivecA7n5vSSmU8zGcsV3UHUC6c-isT4fLAmMDCbJ_JkVqdyKmLbqyohMlGzL4XCkotwuic2z1jqt2EU3JcJhOG5vDEh4tbF40P7K49r5tCFs7EFyUIvTamF5Al27KKirouhKXa1vilnGyY/s320/1.png" /></a></div> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />Now the database is created, you can create some tables and enter some data into the database, if you wish, Otherwise proceed like this: <br /> <br /><strong>Step1: Make the database OFFLINE.</strong> <br /><br /><span style="color: blue;">USE </span>[master]<br /><span style="color: blue;">GO</span><br /><span style="color: blue;">ALTER DATABASE</span> TestDB <span style="color: blue;">SET OFFLINE</span><br /><br /><strong>Step2: Move file Physically</strong> <br />Now you need to move that file physically from existing folder to the new the location. Open the parent folder (Here 'C:\MSSQL\DATA') , You can see both mdf and ldf files', make sure that you cut the appropriate file, in this example it is the Log file. Cut that "TestDB_log.LDF" file and paste it on "D:\MSSQL\Data" <br /> <br /><strong>Step3: Update the system reference</strong> <br />Once you move the file physically , you need to update the system reference using the ALTER DATABASE .. MODIFY FILE Command as shown below: <br /> <br /><span style="color: blue;">ALTER DATABASE </span>TestDB <br /><span style="color: blue;">MODIFY FILE</span> ( <br /> NAME =<span style="color: red;">'TestDB_log'</span><br /> ,<span style="color: blue;">FILENAME</span> = <span style="color: red;">'D:\MSSQL\Data\TestDB.LDF'</span><br />)<br /><br /><strong>Step5 : Make database ONLINE </strong><br />Last step is to make database online as shown below:<br /><br /><span style="color: blue;">ALTER DATABASE <span style="color: black;">TestDB </span>SET ONLINE</span><br /><span style="color: blue;">GO</span><br /><br />We are done. Now check existing files location using query mentioned above.</div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-69627953403497765002011-05-05T17:32:00.000-07:002013-03-23T13:09:40.422-07:00Sequence Container in SSIS - Different ways of using Sequence Containers<div dir="ltr" style="text-align: left;" trbidi="on">Integration Services includes the Sequence container, which makes it simple to divide the control flow in a package into groups of tasks and containers that you can manage as a unit.<br />Using Sequence containers lets you handle the control flow in a package in more detail, without having to manage individual tasks and containers.<br />If a package has many tasks, it can be helpful to group the tasks in Sequence containers.<br /><br />I'll explain different scenarios where Sequence Container paly an important role to implement business rules.<br /><br /><strong>Scenario 1:</strong><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmbLCq2nbAZ83YHhHB7QnfCbwNyLuKGjtgPBgZtasPfSV8JofLg5rfppmWyG2kbpu_LhzGuFXPTkw9uRRPG9Q5qfPNqG5phKPlVRZ-f56WOXdEFKm1tXWkihre8ZT4UIR18DRn_L_eYbjq/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" height="345" hw="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmbLCq2nbAZ83YHhHB7QnfCbwNyLuKGjtgPBgZtasPfSV8JofLg5rfppmWyG2kbpu_LhzGuFXPTkw9uRRPG9Q5qfPNqG5phKPlVRZ-f56WOXdEFKm1tXWkihre8ZT4UIR18DRn_L_eYbjq/s400/1.png" width="400" /></a></div><ul><li>Sequence Task <strong>SC1</strong> must execute first. SC1 may have many task with or without precedence constraints. The group of these task must execute prior to any other tasks in the package.</li><li>Sequence Task <strong>SC2</strong> must start after completion of SC1. SC2 must execute irrespective of Failure/Success of SC1.</li><li>Sequence Task <strong>SC3</strong> contains <strong>Maintenence Plan Tasks</strong> and should be followed by SC2. SC3 must execute only after successfully execution of SC2. </li></ul><br /><strong>Scenario 2:</strong><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrs3vIxgoBkWLnqPwih93LUaDg1IUWW3Z1J-ojeWHKhIm5E7lUtAKx0pVD5LeQDoIeYBzeWIpsE6u3XZSWOPSecCSP6jvQP0PFFiRZnWUrvMrRH9PXgMkzpv8V1O9IEJGc5-KLWZnlfwuI/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" height="345" hw="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrs3vIxgoBkWLnqPwih93LUaDg1IUWW3Z1J-ojeWHKhIm5E7lUtAKx0pVD5LeQDoIeYBzeWIpsE6u3XZSWOPSecCSP6jvQP0PFFiRZnWUrvMrRH9PXgMkzpv8V1O9IEJGc5-KLWZnlfwuI/s400/1.png" width="400" /></a></div><ul><li>Sequence Task <strong>SC1</strong> must execute first. </li><li>Sequence Task <strong>SC2 </strong>must start based on logical condition. This condition can be based on package variables. </li><li>Sequence Task <strong>SC3</strong> contains Maintenence Plan Tasks and should be followed by both SC1 and SC2. SC3 must execute after successfully execution of SC1. SC3 should execute regardless of SC2 but if SC2 executes, SC3 must execute after SC2.</li></ul><br /> <strong>Scenario 3</strong>: This is real scenario in many BI applications. <br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQCKJibT856BBdbVlCVLnPWPzXZwwhJdy1O5zgb892p6qw0Qr9OvZVbvJAQj3XRzQSxt7d1OMW5g09u90uJLBCEdShrxExO0c_Icn-sjmdWMTBVHkTAfOdX93xZSGn2Ok3be4KzK-v5zPn/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" height="233" hw="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQCKJibT856BBdbVlCVLnPWPzXZwwhJdy1O5zgb892p6qw0Qr9OvZVbvJAQj3XRzQSxt7d1OMW5g09u90uJLBCEdShrxExO0c_Icn-sjmdWMTBVHkTAfOdX93xZSGn2Ok3be4KzK-v5zPn/s400/1.png" width="400" /></a></div><ul><li>SC1 must execute prior to other task. This Sequence Container may contain many tasks to pull data from hetrogenious data sources.</li><li>SC2 should be followed by SC1. This can be used to Insert/Update dimension tables and fact tables along with intermediate tables (if any). This container may further contain Sub - Sequence Containers e.g. SC2(a) to handle dimension Insert/Update and SC2(b) to update Intermediate and Fact tables. </li><li>SC3 should be followed by SC2. This may contains SSAS Tasks to Build/Prcoess Cubes. This container may also have Sub - Sequence Containers e.g. SC3(a) to check whether Current Month partition exists or not. If <strong>Yes</strong> than <strong>Do Nothing</strong> Else Create <strong>Current Month Partitions </strong>using Script task. SC3(b) can be used to Process Dimensions and Current Month Partitions.</li><li>SC4 can be used for <strong>Maintenence Plan</strong> tasks. If SC3 successfully completed (Evolution operation - Expression and Constraint) than take Backup of Cube, Shrink Datamart and Take Backup of Datamart.</li><li>SC5 can be used for <strong>Recovery</strong> Paln. If SC3 fails, Restore Cube from previos & Latest Backup available.. <br /><br /></li></ul><br />However, there are many more ways of utilizing Sequence Containers. Further, things depends on complexity of business requirement rules defined.</div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com1tag:blogger.com,1999:blog-5098208425613902582.post-80066097167749637052011-03-15T21:42:00.000-07:002013-03-23T13:09:40.517-07:00Foreach Loop Enumerators<div dir="ltr" style="text-align: left;" trbidi="on">The <strong>Foreach Loop</strong> container defines a repeating control flow in a package. The loop implementation is similar to Foreach looping structure in programming languages but in a package, looping is enabled by using a Foreach enumerator. The Foreach Loop container repeats the control flow for each member of a specified enumerator.<br /><br />SSIS provides the following enumerator types:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWDeyyjzcc_F9583wkSg1GsRIzW-WX120xGP6ykRIf5_HrEhg9vRCoZO8JNUQ-2Mi6gkDzMoBBhyphenhyphenDmnrrwCLyO-G3-It8HqhRzl0AXfJy4FFEwT-1kDeO89arVodmmaUbOFeZ6egR-q9tE/s1600/1.png" imageanchor="1" style="cssfloat: left; margin-left: 1em; margin-right: 1em;"><img border="0" height="145" ru="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWDeyyjzcc_F9583wkSg1GsRIzW-WX120xGP6ykRIf5_HrEhg9vRCoZO8JNUQ-2Mi6gkDzMoBBhyphenhyphenDmnrrwCLyO-G3-It8HqhRzl0AXfJy4FFEwT-1kDeO89arVodmmaUbOFeZ6egR-q9tE/s400/1.png" width="400" /></a></div><br /><br /><ul><li><strong>Foreach File Enumerator </strong>to enumerate files in a folder. The enumerator can traverse subfolders. For example, you can read all the files that have the <strong>*.csv</strong> file name extension in the folder and its subfolders.</li><li><strong>Foreach Item Enumerator</strong> to enumerate items that are collections. For example, you can enumerate the names of executables and working directories that an Execute Process task uses.</li><li><strong>Foreach ADO Enumerator</strong> to enumerate rows in tables. For example, you can get the rows in an ADO recordset.</li><li><strong>Foreach ADO.NET Schema Rowset Enumerator</strong> to enumerate the schema information about a data source. For example, you can enumerate and get a list of the tables of your SQL Server database.</li><li><strong>Foreach From Variable Enumerator</strong> to enumerate the object that a specified variable contains. The enumerable object can be an array, an ADO.NET DataTable, an Integration Services enumerator, and so on. For example, you can enumerate the values of an array that contains the name of Servers.</li><li><strong>Foreach Nodelist Enumerator</strong> to enumerate the result set of an XML Path Language (XPath) expression. For example, this expression enumerates and gets a list of all the products of Electronics type: /products/product[@type='Electronics'].</li><li><strong>Foreach SMO Enumerator</strong> to enumerate SQL Server Management Objects (SMO) objects. For example, you can enumerate and get a list of the views in a SQL Server database.</li></ul></div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com0tag:blogger.com,1999:blog-5098208425613902582.post-25030092793440426822011-01-01T23:19:00.000-08:002013-03-23T13:09:40.609-07:00Adding Custom Color in SSRS Chart Reports<div dir="ltr" style="text-align: left;" trbidi="on">Do you ever come across a requirement where you need to use user defined colors instead of default colors in a chart (for example Pie Chart).<br /><br />In this article, I'll explain how to create a <strong>Custom Palette</strong> and how to use that palette in a <strong>Pie Chart</strong>.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilEov8wK_XzlffywLB4TXy3AJKLvnDduD3acvethuQS87tyw4DBi1SVWXaCoPBzlDqywE1dGl1DomAOA1UTp7t9_YhJz9BoeWqUM9gr85EleK8voKMnVjenVWYvc5-PD168stSh393C51L/s1600/Chart1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="127" n4="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilEov8wK_XzlffywLB4TXy3AJKLvnDduD3acvethuQS87tyw4DBi1SVWXaCoPBzlDqywE1dGl1DomAOA1UTp7t9_YhJz9BoeWqUM9gr85EleK8voKMnVjenVWYvc5-PD168stSh393C51L/s400/Chart1.png" width="400" /></a></div>In the above screen-shot, I am using color <strong><span style="color: blue;">Blue</span>, <span style="color: red;">Red</span>, <span style="color: #134f5c;">Teal</span></strong> and <strong><span style="color: #f1c232;">Gold</span></strong> for the first four values of the <strong>Period </strong>column and same colors are used in <strong>Pie Chart</strong> as well.<br /><br />Here are the steps to achieve this task:<br /><br />STEP1:<br />Create your custome color palette in the report using Custom Code in your report. To do so, click <strong>Report</strong> => <strong>Report Properties</strong> => <strong>Code</strong> and copy below code:<br /><br /><span style="font-family: "Courier New", Courier, monospace;">Private colorPalette As String() = { "Blue", "Red", "Teal", "Gold", "Green","#A59D93", "#B8341B", "#352F26", "#F1E7D6", "#E16C56", "#CFBA9B"}</span><br /><br /><span style="font-family: "Courier New", Courier, monospace;">Private count As Integer = 0</span><br /><span style="font-family: "Courier New", Courier, monospace;">Private mapping As New System.Collections.Hashtable()</span><br /><br /><span style="font-family: "Courier New", Courier, monospace;">Public Function GetColor(ByVal groupingValue As String) As String</span><br /><span style="font-family: "Courier New", Courier, monospace;"> If mapping.ContainsKey(groupingValue) Then</span><br /><span style="font-family: "Courier New", Courier, monospace;"> Return mapping(groupingValue)</span><br /><span style="font-family: "Courier New", Courier, monospace;"> End If</span><br /><span style="font-family: "Courier New", Courier, monospace;"> Dim c As String = colorPalette(count Mod colorPalette.Length)</span><br /><span style="font-family: "Courier New", Courier, monospace;"> count = count + 1</span><br /><span style="font-family: "Courier New", Courier, monospace;"> mapping.Add(groupingValue, c)</span><br /><span style="font-family: "Courier New", Courier, monospace;"> Return c</span><br /><span style="font-family: "Courier New", Courier, monospace;">End Function</span><br /><br />You can define your own colors in the above function.<br /><br />STEP2:<br />In the Pie Chart, select <strong>Series Properties</strong> and select the <strong>Fill</strong> option from left side as shown below:<br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRLlroEiqFGuKkGlgPAHFVyJ-nz_GxjLCq92vz7wlAwtYoCzWZtVTEXUzAVsxsUcobpWR0gWpGNt5zH8QLog-IWSisVETkXjWihXX6XtNQr7XAW_qJPWzzwYrGjNM7l_JrqCAFsXSDyXn0/s1600/Chart2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="285" n4="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRLlroEiqFGuKkGlgPAHFVyJ-nz_GxjLCq92vz7wlAwtYoCzWZtVTEXUzAVsxsUcobpWR0gWpGNt5zH8QLog-IWSisVETkXjWihXX6XtNQr7XAW_qJPWzzwYrGjNM7l_JrqCAFsXSDyXn0/s320/Chart2.png" width="320" /></a></div><br />Now write following expression in the <strong>Color</strong> expression:<br /><br /><span style="background-color: #cccccc; font-family: "Courier New", Courier, monospace;">=code.GetColor(Fields!Year.Value)</span><br /><br />Here <strong>Fields!Year.Value</strong> is a field of dataset which is used as Chart <strong>Category</strong> fields.<br /><br />STEP3:<br />In the left most column of the tabular report, insert character <span style="color: black; font-family: Arial; font-size: 8pt; font-style: normal; font-weight: 400; text-decoration: none;">█ </span>and in the <strong>color</strong> property of the textbox write following expression:<br /><br /><span style="background-color: #cccccc; font-family: Courier New;">=code.GetColor(Fields!Year.Value)</span><br /><br />Here I am considing that tabular report is grouped on <strong>Fields!Year.Value </strong>field.<br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGUkKDpRf9FunHtBjppwC0pAhBGJmh-5Q5DtrzVfQhiSBI2w-WiHUJIqChKFZpgU10BtAWOhcluto9Ehq9ykB8VENob7b856rQTK8QwHaDKuwPvEDYJDLpSfP72j8s2Idpr_byz_STsa3_/s1600/Chart3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="115" n4="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGUkKDpRf9FunHtBjppwC0pAhBGJmh-5Q5DtrzVfQhiSBI2w-WiHUJIqChKFZpgU10BtAWOhcluto9Ehq9ykB8VENob7b856rQTK8QwHaDKuwPvEDYJDLpSfP72j8s2Idpr_byz_STsa3_/s320/Chart3.png" width="320" /></a></div><br /><br />Thats it. Click on the preview and enjoy your custom colors in charting.<br /><br />Cheers!!!</div>SQL BI Devhttp://www.blogger.com/profile/05174359128365572180noreply@blogger.com1