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

<channel>
	<title>SQL &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:23:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>SQL &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Foolproof Tips for Reading and Shrinking Transaction logs in SQL Server</title>
		<link>https://sibeeshpassion.com/transaction-log-in-sql-server/</link>
					<comments>https://sibeeshpassion.com/transaction-log-in-sql-server/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Thu, 07 Jun 2018 13:35:37 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Transaction]]></category>
		<category><![CDATA[Transaction logs in SQL]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=12943</guid>

					<description><![CDATA[[toc] Query-1: SQL Server log file growing unexpectedly? “We are wondering why transaction logs keep on increasing?? It become so gigantic, the transaction log size get increase from 135GB to 350GB and that&#8217;s so annoying. My drive containing data store is losing space. I am using Full Recovery Model and the logs are backed up hourly. Please help me out why this is happening and what should be done to stop growing it too big?” SOLVED: SQL Server Log File Getting Too Big SQL Server Transaction logs records all activities of transaction logs. Each database in SQL Server instance consists [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Query-1: SQL Server log file growing unexpectedly?</h2>
<p><i>“We are wondering why transaction logs keep on increasing?? It become so gigantic, the transaction log size get increase from 135GB to 350GB and that&#8217;s so annoying. My drive containing data store is losing space. I am using Full Recovery Model and the logs are backed up hourly. Please help me out why this is happening and what should be done to stop growing it too big?”</i></p>
<h3>SOLVED: SQL Server Log File Getting Too Big</h3>
<p>SQL Server Transaction logs records all activities of transaction logs. Each database in SQL Server instance consists of logs that records all the modification done in the databases. It is crucial component of the databases. Any modification, deletion can be tracked down in transaction logs.</p>
<p>There are various reasons of transaction log file getting expanded. The possible reasons are listed below:</p>
<ul>
<li>Large transaction log file</li>
<li>Transaction taking too long to complete</li>
<li>Transaction operation fail &amp; may start to rollback</li>
<li>Issue in performance</li>
<li>Blocking issue</li>
<li>Database participating in AlwaysOn availability group</li>
</ul>
<h4>What to do for stopping growing log file too big</h4>
<ol>
<li>Change the type of Recovery Model to Simple Recovery Model only if you are fine with not able to restore logs hence, failed point in time recovery. It is because if you are truncating your logs, you are breaking Transaction log LSN &amp; if any disaster occur, you will not able to restore T-logs. Hence if you are fine with this situation, then change your Recovery model to Simple. This will not allow any extra growth of log file.</li>
<li>Take T-log backup every hour in Full recovery Model, your transaction log will keep on growing until you take backup and truncate of it. While taking hourly T-log backup, the logs will grow until one hour, but after this it would truncate all commited transaction.</li>
</ol>
<p>Sometimes it might happen that you are in Simple Recovery Model, but your logs are still growing!!! Reason being is long running transaction. If your transaction taking long time when deleting thousand records in one delete statement, then logs will not be able to truncate until delete operation is done.</p>
<p>You can save yourself by maintaining proper size of log file or monitoring the usage of transaction.</p>
<p>By doing this, you can cut down the size of Transaction log.</p>
<h2>Query-2 How To Shrink Transaction logs File in SQL Server?</h2>
<p><i>“My log file size is growing continuously. Why is this happening?? I am lacking my disk space. I want to shrink my Transaction log file. Can anyone tell me how to shrink transaction logs in SQL Server. What will be the after effects if I shrink the log file. </i></p>
<h3>SOLVED: Reduce SQL Server Database Transaction Log File</h3>
<p>Relax!! There are several reasons for transaction log file growth. Long Running transaction, lack of taking log backup are some of the reasons which result in transaction log growth. Databases running for business purposes or production requires appropriate recovery model to be chosen for log management.</p>
<p>Log truncation frees up the log file space so that logs can reuse it. Truncation occur automatically if the database is backed up in Simple Recovery Model or after log backup when database is in Full Recovery Model.</p>
<p>Here I will resolve your shrink issue by two methods: By using SQL Server Management Studio and by using T-SQL.</p>
<h4><strong>Shrink By SQL Server Management Studio:</strong></h4>
<ul>
<li>Right Click on your Database&#8211;&gt;Tasks&#8211;&gt;Shrink&#8212;&gt;Files.</li>
<li>You will get the <strong>Shrink File</strong> Window, Change the File Type to <strong>Log</strong>.</li>
<li>There are three different actions under Shrink Action option. Either release the unused space, or shrink file to reorganize pages before releasing unused space, or empty file by migrating the data to other files in the same filegroup. Choose it according to your need.</li>
</ul>
<h4><strong>Shrink By T-SQL:</strong></h4>
<p>You can simply shrink transaction log file by running DBCC SHRINKFILE after taking log back. If you are using Simple Recovery Model, run below code:</p>
<p><code> DBCC SHRINKFILE (TestDB_log, 1)</code></p>
<p>If your database is in Full Recovery Model, first of all, set it to Simple Recovery Model, Then run DBCC SHRINKFILE and then set it to full.</p>
<p><strong>Caution:</strong> Setting database again in Full Recovery Model leads to loss of data in the Log. So, if you dont care about losing your log data, then definitely go for it!</p>
<h4><strong>Tips when you plan to shrink database or file: </strong></h4>
<ul>
<li>Shrink operation found to be most effective after delete or drop table operation as it create lot of unused space.</li>
<li>If you are repeatedly shrinking your database and you notice that the size of database grows again. Alert!! Shrinking database is a wasted operation, as most database require free space for regular day-to-day operation. This indicates that the space that was shrunk was a part of regular operation.</li>
<li>You should not shrink your database or data file after rebuilding indexes. As shrinking increases fragmentation to extreme level.</li>
<li>Do not ON Auto_Shrink option. (Unless you have very urgent requirement)</li>
</ul>
<h4>Is Shrinking database Bad?</h4>
<p>Well, Yes.</p>
<p>After shrinking operation,you will definitely be able to reduce the size of the database. But Wait!! Check your Fragmentation level first. It is found to be way too much!!!</p>
<p>Shrink operation increases the value of the fragmentation way too much. And higher fragmentation costs you poor performance of the database.</p>
<p>While if you are thinking that you can reduce fragmentation by using rebuild index, let me alert you, this will definitely reduce your fragmentation level. But Let me check the size of the database The database size increases way higher than the original.</p>
<h2>Query-3 How to check Deleted Records in SQL Server?</h2>
<p><i>“I am working in an organization and my manager assigned me work to check deleted database records of my database. How can I check my deleted records in SQL Server? Please Help me out from this situation.”</i></p>
<h3>SOLVED: Ways to Check Deleted Records in SQL Server</h3>
<p>You can track down your deleted database records by reading Transaction logs. And you can read it by using <strong>fn_dblog</strong> function. You can track down any DML as well as DDL activity like insert, delete , update, create operation by checking your transaction logs.</p>
<p>Fn_dblog function enables users to read all the database activity happening in SQL database. The function require begin and end LSN number for a transaction. You can easily trackdown the information of a person who did changes to your database. As LSN number are not in human readable form, SQL Server provide fn_dblog function for easy reading of transaction logs.</p>
<p>You can simply check your database activity by implementing below code:</p>
<p><code>USE ReadingDBLog;<br />
GO<br />
select [Current LSN],<br />
[Operation],<br />
[Transaction Name],<br />
[Transaction ID],<br />
[Transaction SID],<br />
[SPID],<br />
[Begin Time]<br />
FROM   fn_dblog(null,null)</code></p>
<h4><strong>How to Read Transaction Log Quickly</strong></h4>
<p>One quick way to read SQL Server database activity is to use SysTools <a href="https://www.systoolsgroup.com/sql-log-analyzer.html"><strong>SQL Log Viewer</strong></a>. It read &amp; analyse operation like insert, update, delete. The software previews all .ldf activities like transaction name, table name, query etc. You have option to choose the database from different mode ie Online &amp; Offline mode. You will able to fetch it from live databases. If your database is in Simple Recovery Mode, the tool is capable to recover deleted database records. You will get three different option for exporting. You can export it as in SQL Server Database , as CSV or as Compatible Script.</p>
<h2>Conclusion</h2>
<p>The blog covers various users queries about transaction logs along with its possible solution. I have discussed why transaction logs keep on increasing, how to track down your transaction details of your database and how to shrink transaction logs. I have also discussed some quick tips when you shrink your database.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/transaction-log-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Copy Table Schema and Data from One Database to another Database in SQL Server</title>
		<link>https://sibeeshpassion.com/copy-table-schema-and-data-from-one-to-another-database/</link>
					<comments>https://sibeeshpassion.com/copy-table-schema-and-data-from-one-to-another-database/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Thu, 26 Apr 2018 12:41:04 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database to Database]]></category>
		<category><![CDATA[MSSQL]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=12814</guid>

					<description><![CDATA[[toc] Problem: A few days ago, while migrating data from one database to another, I encountered an interesting problem which user faced a lot. “I have two databases, I have to copy tables data from one database to another. My query is how can I copy table schema from one database to another with its schema and data” In this blog, we will learn the easiest solution on how you can solve that query. Solution There are plenty of methods on how you can copy table schema and data from one database to another like Generate script wizard, Import/Export Wizard [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Problem:</h2>
<p>A few days ago, while migrating data from one database to another, I encountered an interesting problem which user faced a lot.</p>
<p><em>“I have two databases, I have to copy tables data from one database to another. My query is how can I copy table schema from one database to another with its schema and data”</em></p>
<p>In this blog, we will learn the easiest solution on how you can solve that query.</p>
<h2>Solution</h2>
<p>There are plenty of methods on how you can copy table schema and data from one database to another like Generate script wizard, Import/Export Wizard etc. But these methods are quite lengthy and requires users time.</p>
<p>The easiest solution to copy schema’s table from one database to another is to use SysTools SQL Server Database Migration Tool. You will able to migrate your tables schema by performing few steps.</p>
<h3>How to Copy Table Schema and Data from One Database to Another?</h3>
<ul>
<li>Launch <strong><a href="https://www.systoolsgroup.com/sql-server/migration/">SysTools SQL Server Database Migration Tool</a></strong>.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/1.png"><img fetchpriority="high" decoding="async" class="size-medium wp-image-12815" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/1-300x185.png" alt="Launch SysTools SQL Server Database Migration Tool" width="300" height="185" srcset="/wp-content/uploads/2018/04/1-300x185.png 300w, /wp-content/uploads/2018/04/1-768x473.png 768w, /wp-content/uploads/2018/04/1-400x247.png 400w, /wp-content/uploads/2018/04/1-973x600.png 973w, /wp-content/uploads/2018/04/1.png 579w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Click <strong>Open</strong> and load your database MDF file.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/3.png"><img decoding="async" class="size-medium wp-image-12816" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/3-300x185.png" alt="open MDF File" width="300" height="185" srcset="/wp-content/uploads/2018/04/3-300x185.png 300w, /wp-content/uploads/2018/04/3-768x474.png 768w, /wp-content/uploads/2018/04/3-1024x631.png 1024w, /wp-content/uploads/2018/04/3-400x247.png 400w, /wp-content/uploads/2018/04/3-973x600.png 973w, /wp-content/uploads/2018/04/3.png 1025w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Choose the <strong>Scan Modes</strong> accordingly and select the SQL Server version of your .mdf file.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/4.png"><img decoding="async" class="size-medium wp-image-12817" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/4-300x185.png" alt="select version" width="300" height="185" srcset="/wp-content/uploads/2018/04/4-300x185.png 300w, /wp-content/uploads/2018/04/4-768x474.png 768w, /wp-content/uploads/2018/04/4-400x247.png 400w, /wp-content/uploads/2018/04/4-973x600.png 973w, /wp-content/uploads/2018/04/4.png 579w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Select the database table from the left side, which you want to migrate to another database.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/5.png"><img decoding="async" class="size-medium wp-image-12818" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/5-300x185.png" alt="Select the database name" width="300" height="185" srcset="/wp-content/uploads/2018/04/5-300x185.png 300w, /wp-content/uploads/2018/04/5-768x473.png 768w, /wp-content/uploads/2018/04/5-400x247.png 400w, /wp-content/uploads/2018/04/5-973x600.png 973w, /wp-content/uploads/2018/04/5.png 1022w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Click on <strong>Export</strong> for migration process.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/6.png"><img decoding="async" class="size-medium wp-image-12819" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/6-300x185.png" alt="Click export to migrate the data" width="300" height="185" srcset="/wp-content/uploads/2018/04/6-300x185.png 300w, /wp-content/uploads/2018/04/6-768x473.png 768w, /wp-content/uploads/2018/04/6-400x246.png 400w, /wp-content/uploads/2018/04/6-974x600.png 974w, /wp-content/uploads/2018/04/6.png 1023w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>You will get two options for exporting. One is SQL Server Database and other is SQL Server Compatible Script. Choose it according to your need.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/7.png"><img decoding="async" class="size-medium wp-image-12820" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/7-300x247.png" alt="Two option for exporting" width="300" height="247" srcset="/wp-content/uploads/2018/04/7-300x247.png 300w, /wp-content/uploads/2018/04/7-400x329.png 400w, /wp-content/uploads/2018/04/7.png 624w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>After filling the Server credentials, Select the destination database as ‘<strong>Export to Existing database</strong>’</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/8.png"><img decoding="async" class="size-medium wp-image-12821" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/8-300x247.png" alt="Choose your desired destination location" width="300" height="247" srcset="/wp-content/uploads/2018/04/8-300x247.png 300w, /wp-content/uploads/2018/04/8-400x329.png 400w, /wp-content/uploads/2018/04/8.png 624w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Software will fetch the databases and let you select the database on which you want to move the selected table.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/9.png"><img decoding="async" class="size-medium wp-image-12822" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/9-300x247.png" alt="fetch details od database" width="300" height="247" srcset="/wp-content/uploads/2018/04/9-300x247.png 300w, /wp-content/uploads/2018/04/9-400x329.png 400w, /wp-content/uploads/2018/04/9.png 623w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>You will get two options to export. Select ‘<strong>With Schema &amp; Data</strong>’. This option will copy schema &amp; data of your selected table from one database and export it to another and click <strong>Export</strong>.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/11.png"><img decoding="async" class="size-medium wp-image-12823" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/11-300x246.png" alt="Select Schema &amp; Data option" width="300" height="246" srcset="/wp-content/uploads/2018/04/11-300x246.png 300w, /wp-content/uploads/2018/04/11-400x328.png 400w, /wp-content/uploads/2018/04/11.png 625w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>You will get popup of Export complete.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/12.png"><img decoding="async" class="size-medium wp-image-12824" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/12-300x186.png" alt="Export complete" width="300" height="186" srcset="/wp-content/uploads/2018/04/12-300x186.png 300w, /wp-content/uploads/2018/04/12-768x476.png 768w, /wp-content/uploads/2018/04/12-400x248.png 400w, /wp-content/uploads/2018/04/12-969x600.png 969w, /wp-content/uploads/2018/04/12.png 577w" sizes="(max-width: 300px) 100vw, 300px" /></a>
</ul>
<h2>Conclusion</h2>
<p>The blog covers the easiest workaround of mostly faced users query on how to copy schema &amp; data from one database to another. You can also use Import/Export Wizard, Generate script wizard etc for object migration using SQL Server. But these methods has some limitations. In Import/Export wizard, the indexes and the key will not get transferred, you need to generate scripts for that. The export wizard fails if foreign keys connecting the tables together is not in a correct order. ‘Generate script’ method is used to generate a single script for tables schema, data, indexes and keys. But again, the limitation is this method doesn’t generate tables creation script in correct order.</p>
<p>So one can opt for SysTools SQL Database Migration Tool for fast migration of tables schema from one database to another.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/copy-table-schema-and-data-from-one-to-another-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understand the Internal Structure of SQL Database File</title>
		<link>https://sibeeshpassion.com/understand-the-internal-structure-of-sql-database-file/</link>
					<comments>https://sibeeshpassion.com/understand-the-internal-structure-of-sql-database-file/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Thu, 23 Mar 2017 15:55:59 +0000</pubDate>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Database File]]></category>
		<category><![CDATA[SQL Internal Structure]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12149</guid>

					<description><![CDATA[You must have thought how to store data in SQL Server? SQL Server is the platform, which provides a proper management of database. There is no doubt that it follows a strategy for the storage of all the files. All the users of SQL are aware with the fact that database objects are stored in MDF file. MDF files are responsible for the management of data in SQL Server. Therefore, in this article, we will learn the storage system of data in SQL Server data files. Database Files and its Storage Structure in SQL Server Database in SQL Server has [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>You must have thought how to store data in SQL Server? SQL Server is the platform, which provides a proper management of database. There is no doubt that it follows a strategy for the storage of all the files. All the users of SQL are aware with the fact that database objects are stored in MDF file. MDF files are responsible for the management of data in SQL Server. Therefore, in this article, we will learn the storage system of data in SQL Server data files.</p>
<h2>Database Files and its Storage Structure in SQL Server</h2>
<p>Database in SQL Server has two operating system files:</p>
<ul>
<li>Data Files</li>
<li>Log File</li>
</ul>
<p><strong>Data Files</strong></p>
<p>A data file consists of objects and data. Depending upon the needs, data files can be divided into two types: </p>
<p><strong>Primary Database File</strong></p>
<p>Each database has one primary data file. All the tables, database objects, indexes and views are stored in that file. The file extension of primary database file is .mdf. </p>
<p><strong>Secondary Database File</strong></p>
<p>This type is used at the time of exceeding the maximum allocated size for an individual file on Windows. It helps the database to increase in size. File extension for this file is .ndf.</p>
<p><strong>Log File</strong></p>
<p>Whenever users want to recover whole of the database in SQL Server, they require certain information, which are inside a log file. For one database there will be one log file and transactions of database are written on it even before to the data file. The file extension used by it is .ldf. LDF stands for Transactional Log file.</p>
<p><strong>Inner Structure of Data File</strong></p>
<p>Each database has its space to store the data, which is divided into different pages that are numbered from 0 to N. During the expansion of database files from its default size, those pages which are created newly are numbered from the last highest page number plus 1. In the similar way, at the time of shrinking of files it eliminates pages in decreasing order, which in the same manner starts from the highest page number. The basic unit of I/O for SQL Server operations is a page and each page is of 8 KB. A data file is a large array of pages. SQL Server stores different data with the help of multiple pages, Some of them are GAM, Index, IAM, Data, SGAM, and TextMix.</p>
<p><strong>Page Addressing:</strong></p>
<p>Now, if we analyze the pages addressing then we can see that every page in SQL Server is of equal size that is 8192 bytes. Each page has its own address, which is unique. It is a part of single database file. The ID of the file makes the first part of the unique address. Pages are numbered starting from 0. This is the mentioned format in which page address is written:</p>
<p> <strong>file number</strong>  :  <strong>page number</strong> </p>
<p>Data page is very essential among the page types. This is used for the storage of records to a database. </p>
<p>Structure of Data Page:</p>
<p>A data page contains three sections.</p>
<ul>
<li>Page Header</li>
<li>Page Body</li>
<li>Slot Array or Row offset</li>
</ul>
<p><strong>Page Header (0-95 bytes)</strong></p>
<p>The first 96 bytes of a particular page is known as page header, which consists of the information of the page.</p>
<p>That is, Page ID, No of records in that page and IDs of previous/next pages.</p>
<p><strong>Page Body</strong></p>
<p>It is that part where actual data is stored. It is followed by the free space and slot array. </p>
<p><strong>Slot Array</strong></p>
<p>Slot array, also known as off-set array, is an array of two-byte values, which is read by the SQL Server in reverse i.e. from the very end of the page. Slot array keep slot points to a byte in the page wherever a record begins. First slot of the record slot array is saved in the last two bytes of the page that points to the page of the first record saved at the page. </p>
<p><strong>Conclusion</strong></p>
<p>One of the essential things that should be kept in mind is that, In SQL Server, the database file (.mdf) store its data as per 8 kb pages and it is important for SQL Server to sustain the sequence of data pages as per their header information. In case of mismatching of information or the data is not stored in sequential order into data pages, there is possibility in the corruption of database or you may face <a href="http://www.sqlrecoverytool.com/fix-ms-sql-server-error-5172.html" target="_blank">SQL database error like 5172</a>, which is a header corruption error.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/understand-the-internal-structure-of-sql-database-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Keyboard Query Shortcuts In SQL Server Management Studio</title>
		<link>https://sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/</link>
					<comments>https://sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 12 May 2016 00:00:53 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[Keyboard Shortcuts]]></category>
		<category><![CDATA[Query Shortcuts]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11543</guid>

					<description><![CDATA[In this article we are going to see some shortcuts that may be useful to you when you work with SQL Server Management Studio. You can always uses some custom queries too as query shortcuts in SSMS. Here I am going to show some most used the queries shortcuts. I hope you will like this. Background If you are a dot net developer or if you are working with any Microsoft technologies, you must have some experience in working with SQL and SQL Server Management Studio. But as a developer we always try to achieve the things in a simple [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we are going to see some shortcuts that may be useful to you when you work with SQL Server Management Studio. You can always uses some custom queries too as query shortcuts in SSMS. Here I am going to show some most used the queries shortcuts. I hope you will like this.</p>
<p><strong>Background</strong></p>
<p>If you are a dot net developer or if you are working with any Microsoft technologies, you must have some experience in working with SQL and SQL Server Management Studio. But as a developer we always try to achieve the things in a simple manner. Isn&#8217;t it? This is where we are going for keyboard shortcuts. We do have an option to set and use the keyboard shortcuts in SSMS too. I will explain those. </p>
<p><strong>Keyboard Query Shortcuts In SSMS</strong></p>
<p>First of all let me tell you an example of where we can use the keyboard shortcuts. We know how to create stored procedures right? There procedures are created in a folder called &#8216;Stored Procedures&#8217; under Programmability. Now let us assume that I have a stored procedure with name as <em>usp_Get_SalesOrderDetail</em>. Now if you need to see the queries we have written in that stored procedure, what will you do? You have two options,</p>
<li>Right click on the stored procedure and click on modify</li>
<li>Use the sp_helptext as <em>sp_helptext usp_Get_SalesOrderDetail</em></li>
<p>Now my question is, in this scenario, whenever you need to see the stored procedure you need to type sp_helptext right? How can we overcome this situation? Here we can set the keyboard shortcuts. </p>
<p><strong>Setting the keyboard shortcuts</strong></p>
<p>Go to Tools -> Options.</p>
<div id="attachment_11544" style="width: 359px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Tools_Options_.png"><img decoding="async" aria-describedby="caption-attachment-11544" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Tools_Options_.png" alt="Tools_Options" width="349" height="208" class="size-full wp-image-11544" srcset="/wp-content/uploads/2016/04/Tools_Options_.png 349w, /wp-content/uploads/2016/04/Tools_Options_-300x179.png 300w" sizes="(max-width: 349px) 100vw, 349px" /></a><p id="caption-attachment-11544" class="wp-caption-text">Tools_Options</p></div>
<p>Go to Environment -> Keyboard -> Query Shortcuts </p>
<div id="attachment_11545" style="width: 252px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png"><img decoding="async" aria-describedby="caption-attachment-11545" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png" alt="Environment_Keyboard_Query_Shortcuts_" width="242" height="341" class="size-full wp-image-11545" srcset="/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png 242w, /wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_-213x300.png 213w" sizes="(max-width: 242px) 100vw, 242px" /></a><p id="caption-attachment-11545" class="wp-caption-text">Environment_Keyboard_Query_Shortcuts_</p></div>
<p>On the right side you can see some shortcuts which are by default in SSMS. Now if you need to add a new one, just click on any column under Stored Procedure column.  </p>
<div id="attachment_11546" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png"><img decoding="async" aria-describedby="caption-attachment-11546" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png" alt="Adding_a_new_keyboard_shortcut" width="650" height="378" class="size-full wp-image-11546" srcset="/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png 650w, /wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975-300x174.png 300w, /wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975-400x233.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11546" class="wp-caption-text">Adding_a_new_keyboard_shortcut</p></div>
<p>Click OK. Now please go to a query window and select the stored procedure then press CTRL+3, it will show the stored procedure. </p>
<div id="attachment_11547" style="width: 352px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/sp_helptext_Results_.png"><img decoding="async" aria-describedby="caption-attachment-11547" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/sp_helptext_Results_.png" alt="sp_helptext_Results_" width="342" height="441" class="size-full wp-image-11547" srcset="/wp-content/uploads/2016/04/sp_helptext_Results_.png 342w, /wp-content/uploads/2016/04/sp_helptext_Results_-233x300.png 233w" sizes="(max-width: 342px) 100vw, 342px" /></a><p id="caption-attachment-11547" class="wp-caption-text">sp_helptext_Results_</p></div>
<p>No if you need to select all the records from a table when you select the table and press CTRL+5(You can select any key). You can make the shortcut as follows. </p>
<div id="attachment_11548" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Selct_Query_As_Keyboard_Shortcut-e1461589819987.png"><img decoding="async" aria-describedby="caption-attachment-11548" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Selct_Query_As_Keyboard_Shortcut-1024x438.png" alt="Selct_Query_As_Keyboard_Shortcut" width="634" height="271" class="size-large wp-image-11548" /></a><p id="caption-attachment-11548" class="wp-caption-text">Selct_Query_As_Keyboard_Shortcut</p></div>
<p>Now please go ahead and select the table name from the query window and press CTRL+4(The key we selected). I hope you got the result as expected. Have a happy coding!.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed</title>
		<link>https://sibeeshpassion.com/rule-oracle-jre-7-update-51-64-bit-or-higher-is-required-for-polybase-failed/</link>
					<comments>https://sibeeshpassion.com/rule-oracle-jre-7-update-51-64-bit-or-higher-is-required-for-polybase-failed/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 28 Mar 2016 00:00:29 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Rule Check Result]]></category>
		<category><![CDATA[SQL Errors]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server RC 1]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11435</guid>

					<description><![CDATA[In this article we will are going to see how we can fix the error Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed. You may get this error when you try to install SQL Server. I wast trying to install SQL Server 2016 Release Candidate 1, and I got this error while installation. The complete error is like this Rule Check Result, Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed. This computer does not have the Oracle Java SE Runtime Environment Version 7 Update 51 (64-bit) or higher [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we will are going to see how we can fix the error <em>Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed</em>. You may get this error when you try to install <a href="http://sibeeshpassion.com/category/sql/" target="_blank">SQL </a>Server. I wast trying to install SQL Server 2016 Release Candidate 1, and I got this error while installation. The complete error is like this <em>Rule Check Result, Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed. This computer does not have the Oracle Java SE Runtime Environment Version 7 Update 51 (64-bit) or higher installed. The Oracle Java SE Runtime Environment is software provided by a third party. Microsoft grants you no rights for such third-party software. You are responsible for and must separately locate, read and accept applicable third-party license terms.</em> I have fixed this issue, and here I am going to share you how you can also fix this error. I hope you will like this.</p>
<p><strong>Background</strong></p>
<p>As you all know, <a href="http://sibeeshpassion.com/category/Microsoft/" target="_blank">Microsoft </a> has already released SQL Server 2018 RC Version 1. So I wanted to give a try, and I decided to install the same. But at a stage in installation, I got an error which was not allowing me to continue further. I started to scratch my head. And finally I could find the solution. Here we will see that.</p>
<p><strong>Fix to Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed</strong></p>
<p>Once you have started the installation, you can see a window as follows. </p>
<div id="attachment_11436" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479.png"><img decoding="async" aria-describedby="caption-attachment-11436" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479.png" alt="Installation Center SQL Server Start" width="650" height="492" class="size-full wp-image-11436" srcset="/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479.png 650w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479-300x227.png 300w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479-400x303.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11436" class="wp-caption-text">Installation Center SQL Server Start</p></div>
<p>If you have not installed SQL Server yet, you must select &#8220;New SQL Server stand-alone installation&#8221;, or you can upgrade by selecting &#8220;Upgrade from a previous version&#8221;. So we have started installing the things. When you are step away to finish everything once you have selected the features to add. You will be getting the error as follows. </p>
<blockquote><p>
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Rule Check Result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed.</p>
<p>This computer does not have the Oracle Java SE Runtime Environment Version 7 Update 51 (64-bit) or higher installed. The Oracle Java SE Runtime Environment is software provided by a third party. Microsoft grants you no rights for such third-party software. You are responsible for and must separately locate, read and accept applicable third-party license terms. To continue, download the Oracle SE Java Runtime Environment from http://go.microsoft.com/fwlink/?LinkId=526030.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
OK<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
</p></blockquote>
<p>As it is mentioned in the link provided in the link, you can always download and install the Java SE from that link. This link will be redirected to <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" target="_blank">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a>. </p>
<div id="attachment_11437" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Java-SE-e1459094342113.png"><img decoding="async" aria-describedby="caption-attachment-11437" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Java-SE-1024x562.png" alt="Java SE" width="634" height="348" class="size-large wp-image-11437" /></a><p id="caption-attachment-11437" class="wp-caption-text">Java SE</p></div>
<p>Now we have an another option that to disable the Java SE from the features selected. For that go back to the feature selection.</p>
<div id="attachment_11438" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609.png"><img decoding="async" aria-describedby="caption-attachment-11438" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609.png" alt="Feature Selection Installation Center SQL Server" width="650" height="495" class="size-full wp-image-11438" srcset="/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609.png 650w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609-300x228.png 300w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609-400x305.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11438" class="wp-caption-text">Feature Selection Installation Center SQL Server</p></div>
<p>Now Uncheck the selection <em>PolyBase query service for external data</em>.</p>
<div id="attachment_11439" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116.png"><img decoding="async" aria-describedby="caption-attachment-11439" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116.png" alt="Feature Selection Installation Center SQL Server Uncheck Polybase Query Service" width="650" height="490" class="size-full wp-image-11439" srcset="/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116.png 650w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116-300x226.png 300w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116-400x302.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11439" class="wp-caption-text">Feature Selection Installation Center SQL Server Uncheck Polybase Query Service</p></div>
<p>Now you can go ahead and click next. At last, you will get the success message.</p>
<div id="attachment_11440" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394.png"><img decoding="async" aria-describedby="caption-attachment-11440" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394.png" alt="Installation Center SQL Server Success" width="650" height="489" class="size-full wp-image-11440" srcset="/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394.png 650w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394-300x226.png 300w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394-400x301.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11440" class="wp-caption-text">Installation Center SQL Server Success</p></div>
<p>Hooray, we have successfully installed our new version of SQL Server. That&#8217;s fantastic right? Have a happy coding.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/rule-oracle-jre-7-update-51-64-bit-or-higher-is-required-for-polybase-failed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Stored Procedure With Common Table Expression Or CTE</title>
		<link>https://sibeeshpassion.com/stored-procedure-with-common-table-expression-or-cte-2/</link>
					<comments>https://sibeeshpassion.com/stored-procedure-with-common-table-expression-or-cte-2/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 29 Feb 2016 00:00:31 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Common Table Expression]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[Paging Query In SQL]]></category>
		<category><![CDATA[ROW_NUMBER]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11304</guid>

					<description><![CDATA[In this post we will see how to use common table expression or CTE in our SQL Server. There are so many situations that you may need to use a common table expression. I had a situation of returning ROW_NUMBER variable value for my paging query in SQL, for this I used CTE. A common table expression is actually a temporary result set or a table whose scope is defined or limited to the current statement. In this post I will explain the same in detail. I hope you will like this. Background I had a situation of using a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will see how to use common table expression or CTE in our <a href="http://sibeeshpassion.com/category/database/sql/" target="_blank">SQL</a> Server. There are so many situations that you may need to use a common table expression. I had a situation of returning <em>ROW_NUMBER</em> variable value for my paging query in SQL, for this I used CTE. A common table expression is actually a temporary result set or a table whose scope is defined or limited to the current statement.  In this post I will explain the same in detail. I hope you will like this. </p>
<p><strong>Background</strong></p>
<p>I had a situation of using a paging query for one of my application which actually load data to a grid on demand, like when user scrolls or do an y paging. For this I needed to create a stored procedure which accepts page offset as a parameter and return the data accordingly. I used Common Table Expression for the same. </p>
<p><strong>When to use a CTE</strong></p>
<p>There are some situations that you may need to use a CTE, few of them are listed below. </p>
<li>When you are working with recursive queries.</li>
<li>When you need to reference a temporary variable in your query.</li>
<li>You can create temporary views by using CTE, so that you do not need to store the details as view.</li>
<p><strong>Using the code</strong></p>
<p>I hope you all got an idea about CTE, now we can see the basic structure of a common table expression. </p>
<p>[sql]<br />
WITH CTE_Name(Column_Names,&#8230;) AS<br />
  (<br />
	&#8211;Select Query<br />
  )<br />
SELECT *<br />
FROM CTE_Name<br />
WHERE Column_Names1&gt;=Your Condition<br />
END<br />
[/sql]</p>
<p>With the above structure I have created my own stored procedure as follows. </p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO<br />
/****** Object:  StoredProcedure [dbo].[usp_Get_SalesOrderDetailPage]    Script Date: 25-Feb-16 12:53:07 PM ******/<br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
&#8212; =============================================<br />
&#8212; Author:		&lt;Author,Sibeesh Venu&gt;<br />
&#8212; Create date: &lt;Create Date, 18-Feb-2016&gt;<br />
&#8212; Description:	&lt;Description,To fetch SalesOrderDetail Page Wise&gt;<br />
&#8212; =============================================<br />
ALTER PROCEDURE [dbo].[usp_Get_SalesOrderDetailPage] @pageOffset int=0 AS BEGIN &#8212; SET NOCOUNT ON added to prevent extra result sets from<br />
 &#8212; interfering with SELECT statements.</p>
<p>SET NOCOUNT ON;</p>
<p>WITH CTE_Sales(SlNo, SalesOrderID,SalesOrderDetailID,CarrierTrackingNumber,OrderQty,ProductID,UnitPrice,ModifiedDate) AS<br />
  ( SELECT ROW_NUMBER() over (<br />
                              ORDER BY ModifiedDate DESC) AS SlNo,<br />
                        SalesOrderID,<br />
                        SalesOrderDetailID,<br />
                        CarrierTrackingNumber,<br />
                        OrderQty,<br />
                        ProductID,<br />
                        UnitPrice,<br />
                        ModifiedDate<br />
   FROM dbo.SalesOrderDetail)<br />
SELECT *<br />
FROM CTE_Sales<br />
WHERE SlNo&gt;=@pageOffset<br />
  AND SlNo&lt;@pageOffset+10 END</p>
<p>&#8211;[usp_Get_SalesOrderDetailPage] 4<br />
[/sql]</p>
<p>As you can see in the select query I am using a temporary column <em>SlNo</em> which actually a result of <em>ROW_NUMBER()</em>. So to use this query in a where condition I was forced to use the CTE. Now let us run our stored procedure and see the output.</p>
<p><strong>Output</strong></p>
<div id="attachment_11305" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Stored-Procedure-With-Common-Table-Expression-Or-CTE-e1456392062638.png"><img decoding="async" aria-describedby="caption-attachment-11305" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Stored-Procedure-With-Common-Table-Expression-Or-CTE-e1456392062638.png" alt="Stored Procedure With Common Table Expression Or CTE" width="650" height="335" class="size-full wp-image-11305" srcset="/wp-content/uploads/2016/02/Stored-Procedure-With-Common-Table-Expression-Or-CTE-e1456392062638.png 650w, /wp-content/uploads/2016/02/Stored-Procedure-With-Common-Table-Expression-Or-CTE-e1456392062638-300x155.png 300w, /wp-content/uploads/2016/02/Stored-Procedure-With-Common-Table-Expression-Or-CTE-e1456392062638-400x206.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11305" class="wp-caption-text">Stored Procedure With Common Table Expression Or CTE</p></div>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Did you try CTE in your query? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/stored-procedure-with-common-table-expression-or-cte-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>TagIt Control With Data From Database Using Angular JS In MVC Web API</title>
		<link>https://sibeeshpassion.com/tagit-control-with-data-from-database-using-angular-js-in-mvc-web-api/</link>
					<comments>https://sibeeshpassion.com/tagit-control-with-data-from-database-using-angular-js-in-mvc-web-api/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 25 Feb 2016 00:00:46 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Web API]]></category>
		<category><![CDATA[Angular JS]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[TagIt]]></category>
		<category><![CDATA[TagIt Tags From Database]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11245</guid>

					<description><![CDATA[In this article we will learn how to load the tags from database in MVC Web API using Angular JS. Here we are going to use a pretty control called tagIt which does the tag part easier with a lot of configuration options. This article use a normal MVC application which includes the Web API control in it, in addition to it, we uses Angular JS for our client side operations. You can always get the tips/tricks/blogs about these mentioned technologies from the links given below. AngularJS Tips, Tricks, Blogs MVC Tips, Tricks, Blogs Web API Tips, Tricks, Blogs As [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we will learn how to load the tags from database in MVC Web API using Angular JS. Here we are going to use a pretty control called tagIt which does the tag part easier with a lot of configuration options. This article use a normal MVC application which includes the Web API control in it, in addition to it, we uses Angular JS for our client side operations. You can always get the tips/tricks/blogs about these mentioned technologies from the links given below. </p>
<li><a href="http://sibeeshpassion.com/category/angularjs/" target="_blank" rel="noopener">AngularJS Tips, Tricks, Blogs</a></li>
<li><a href="http://sibeeshpassion.com/category/mvc/" target="_blank" rel="noopener">MVC Tips, Tricks, Blogs</a></li>
<li><a href="http://sibeeshpassion.com/category/web-api/" target="_blank" rel="noopener">Web API Tips, Tricks, Blogs</a></li>
<p>As the article title implies, we are actually going to load the tags from a table called tblTags from <a href="http://sibeeshpassion.com/category/SQL/" target="_blank" rel="noopener">SQL </a>Server database.  So now we will go and create our application. I hope you will like this. </p>
<p><strong>Download the source code</strong></p>
<p>You can always download the source code here: <a href="https://code.msdn.microsoft.com/TagIt-Control-With-Data-aa3371f7" target="_blank" rel="noopener">Load Tags From Database Using Angular JS In MVC Web API</a></p>
<p><strong>Background</strong></p>
<p>Few days back I was trying to use the tagIt widget in one of my application. I could do that with some pre defined tags as a variable. Then I thought why don&#8217;t we try some thing like loading these tags from database. Hence my application uses MVC architecture, I selected Web API for retrieving the data from database. I hope someone can find this useful.</p>
<p><strong>Create a MVC application</strong></p>
<p>Click File-> New-> Project then select MVC application.  Before going to start the coding part, make sure that all the required extensions/references are installed. Below are the required things to start with. </p>
<li>Angular JS</li>
<li>TagIt Plugin</li>
<li>jQuery</li>
<p>You can all the items mentioned above from NuGet. Right click on your project name and select Manage NuGet packages.</p>
<div id="attachment_11235" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png"><img decoding="async" aria-describedby="caption-attachment-11235" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png" alt="Manage NuGet Package Window" width="650" height="432" class="size-full wp-image-11235" srcset="/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png 650w, /wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396-300x199.png 300w, /wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396-400x266.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11235" class="wp-caption-text">Manage NuGet Package Window</p></div>
<p>Once you have installed those items, please make sure that all the items(jQuery, Angular JS files, Tag It JS files like tag-it.js) are loaded in your scripts folder. </p>
<p><strong>Using the code</strong></p>
<p>Before going to load the tags from a database we will try to load our tagit control with some predefined array values. No worries, later we will change this array values to the values we get from database. </p>
<p><em>Include the references in your _Layout.cshtml</em></p>
<p>As we have already installed all the packages we need, now we need to add the references, right?</p>
<p>[html]<br />
@RenderBody()</p>
<p>    @Scripts.Render(&quot;~/bundles/jquery&quot;)<br />
    &lt;script src=&quot;~/Scripts/jquery-2.2.0.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Content/jquery-ui.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/angular.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/angular-route.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/tag-it.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;~/Scripts/MyScripts/TagScripts.js&quot;&gt;&lt;/script&gt;<br />
    @RenderSection(&quot;scripts&quot;, required: false)<br />
[/html]</p>
<p>Here <em>TagScripts.js</em> is the JavaScript file where we are going to write our own scripts.  </p>
<p><em>Set the changes in View</em></p>
<p>So we have added the references, now we will make the changes in our view. As we uses Angular JS, we will set our ng-app and ng-controller as follows. </p>
<p>[html]<br />
&lt;div ng-app=&quot;tagApp&quot;&gt;<br />
    &lt;div ng-controller=&quot;tagController&quot;&gt;<br />
        &lt;ul id=&quot;tags&quot;&gt;&lt;/ul&gt;<br />
        &lt;div id=&quot;error&quot;&gt;Nothing found!&lt;/div&gt;<br />
    &lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>You can give a style as follows if you want.</p>
<p>[css]<br />
&lt;style&gt;<br />
    #tags {<br />
        width: 25%;<br />
    }</p>
<p>    #error {<br />
        display:none;<br />
        font-weight: bold;<br />
        color: #1c94c4;<br />
        font-family: Trebuchet MS,Tahoma,Verdana,Arial,sans-serif;<br />
        font-size: 1.1em;<br />
    }<br />
&lt;/style&gt;<br />
[/css]</p>
<p>Oops!, I forgot to mention, please do not forget to include the CSS style sheets. </p>
<p>[html]<br />
&lt;link href=&quot;~/Content/jquery-ui.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
&lt;link href=&quot;~/Content/jquery.tagit.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
[/html]</p>
<p>Now we can write the scripts in our TagScripts.js file. </p>
<p><em>Create Angular App</em></p>
<p>You can create an Angular module as follows. </p>
<p>[js]<br />
var app;<br />
    //Angular App<br />
    app = angular.module(&#8216;tagApp&#8217;, []);<br />
[/js]</p>
<blockquote><p>Here the module name must be same as we have given in ng-app in our view. </p></blockquote>
<p><em>Create Angular Controller</em></p>
<p>You can create an Angular Controller as follows. </p>
<p>[js]<br />
app.controller(&#8216;tagController&#8217;, function ($scope) {<br />
        $(&quot;#tags&quot;).tagit({<br />
            availableTags: availableTags,<br />
            autocomplete: { delay: 0, minLength: 1 },<br />
            beforeTagAdded: function (event, ui) {<br />
                if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                    $(&#8216;#error&#8217;).show();<br />
                    return false;<br />
                } else {<br />
                    $(&#8216;#error&#8217;).hide();<br />
                }<br />
            }<br />
        });<br />
    });<br />
[/js]</p>
<p>As you can see we have called tagit() function to initialize the tagit control. Below are the explanations to the options we have given.</p>
<li>availableTags</li>
<p>availableTags are the source we need to apply to the control so that the given items can be shown on user actions. </p>
<li>autocomplelte</i>
<p>autocomplete is a property which enables the auto complete option, when it is true user will get the items listed accordingly for each key press</p>
<li>beforeTagAdded</li>
<p>beforeTagAdded is a callback function which gets fired before we add the new tags to the control. This function can be used to do all the needed tasks before adding the given item to the control. For example, if we need to load only the values from the database and if we need to restrict creating the new tags by the user, means user will be allowed to use only the available tags which is in the available tag array. The preceding code block does what has been explained above.</p>
<p>[js]<br />
if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                    $(&#8216;#error&#8217;).show();<br />
                    return false;<br />
                } else {<br />
                    $(&#8216;#error&#8217;).hide();<br />
                }<br />
[/js]</p>
<p>If user tries to add a new tag, we will show the alert div which we already set in our view.</p>
<p>Now it is time to see the control in our view, let us see whether it works fine, if not, we may need to go back and checks again.  </p>
<div id="attachment_11260" style="width: 562px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array.png"><img decoding="async" aria-describedby="caption-attachment-11260" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array.png" alt="Tag_It_Control_Defined_Array" width="552" height="169" class="size-full wp-image-11260" srcset="/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array.png 552w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array-300x92.png 300w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array-400x122.png 400w" sizes="(max-width: 552px) 100vw, 552px" /></a><p id="caption-attachment-11260" class="wp-caption-text">Tag_It_Control_Defined_Array</p></div>
<div id="attachment_11261" style="width: 557px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found.png"><img decoding="async" aria-describedby="caption-attachment-11261" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found.png" alt="Tag_It_Control_Defined_Array_If_Nothing_Found" width="547" height="135" class="size-full wp-image-11261" srcset="/wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found.png 547w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found-300x74.png 300w, /wp-content/uploads/2016/02/Tag_It_Control_Defined_Array_If_Nothing_Found-400x99.png 400w" sizes="(max-width: 547px) 100vw, 547px" /></a><p id="caption-attachment-11261" class="wp-caption-text">Tag_It_Control_Defined_Array_If_Nothing_Found</p></div>
<p>It seems everything is fine, thank god we don&#8217;t need any debugging 🙂</p>
<p>Now we will create a Web API controller. Oh yeah, we are going to start our real coding. Right click on your controller folder and click new.</p>
<div id="attachment_11238" style="width: 614px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Web_API_controller.png"><img decoding="async" aria-describedby="caption-attachment-11238" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Web_API_controller.png" alt="Web_API_controller" width="604" height="396" class="size-full wp-image-11238" srcset="/wp-content/uploads/2016/02/Web_API_controller.png 604w, /wp-content/uploads/2016/02/Web_API_controller-300x197.png 300w, /wp-content/uploads/2016/02/Web_API_controller-400x262.png 400w" sizes="(max-width: 604px) 100vw, 604px" /></a><p id="caption-attachment-11238" class="wp-caption-text">Web_API_controller</p></div>
<p>So our Web API controller is ready, then it is time to go to do some Angular JS scripts, don&#8217;t worry we will come back here. </p>
<p>We need to make changes to our Angular JS controller <em>tagController </em> as follows. </p>
<p>[js]<br />
    //Angular Controller<br />
    app.controller(&#8216;tagController&#8217;, function ($scope, tagService) {<br />
        //Angular service call<br />
        var tgs = tagService.getTags();<br />
        if (tgs != undefined) {<br />
            tgs.then(function (d) {<br />
                availableTags = [];<br />
                for (var i = 0; i &lt; d.data.length; i++) {<br />
                    availableTags.push(d.data[i].tagName);<br />
                }</p>
<p>                $(&quot;#tags&quot;).tagit({<br />
                    availableTags: availableTags,<br />
                    autocomplete: { delay: 0, minLength: 1 },<br />
                    beforeTagAdded: function (event, ui) {<br />
                        if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                            $(&#8216;#error&#8217;).show();<br />
                            return false;<br />
                        } else {<br />
                            $(&#8216;#error&#8217;).hide();<br />
                        }<br />
                    }<br />
                });<br />
                console.log(JSON.stringify(availableTags));<br />
            }, function (error) {<br />
                console.log(&#8216;Oops! Something went wrong while fetching the data.&#8217;);<br />
            });<br />
        }<br />
    });<br />
[/js]</p>
<p>As you have noticed, we are calling an Angular JS service here. Once we get the data from the service, we are assigning it to the array which we have initialized with the predefined values, so that the data from the database will be available in the tagit control. So can we create our Angular JS service?</p>
<p>[js]<br />
    //Angular Service<br />
    app.service(&#8216;tagService&#8217;, function ($http) {<br />
        //call the web api controller<br />
        this.getTags = function () {<br />
            return $http({<br />
                method: &#8216;get&#8217;,<br />
                url: &#8216;api/tag&#8217;<br />
            });<br />
        }<br />
    });<br />
[/js]</p>
<p>This will fire our Web API controller and action GET api/tag. And the Web API controller will give you the results which we will format again and give to the available tag array. Sounds cool? Wait, we can do all these stuffs without Angular JS, means we can simply call a jQuery Ajax Get. Do you want to see how? Here it is. </p>
<p>[js]<br />
/* Using jQuery */</p>
<p>$(function () {<br />
    var availableTags = [<br />
      &quot;ActionScript&quot;,<br />
      &quot;AppleScript&quot;,<br />
      &quot;Asp&quot;,<br />
      &quot;BASIC&quot;,<br />
      &quot;C&quot;,<br />
      &quot;C++&quot;,<br />
      &quot;Clojure&quot;,<br />
      &quot;COBOL&quot;,<br />
      &quot;ColdFusion&quot;,<br />
      &quot;Erlang&quot;,<br />
      &quot;Fortran&quot;,<br />
      &quot;Groovy&quot;,<br />
      &quot;Haskell&quot;,<br />
      &quot;Java&quot;,<br />
      &quot;JavaScript&quot;,<br />
      &quot;Lisp&quot;,<br />
      &quot;Perl&quot;,<br />
      &quot;PHP&quot;,<br />
      &quot;Python&quot;,<br />
      &quot;Ruby&quot;,<br />
      &quot;Scala&quot;,<br />
      &quot;Scheme&quot;<br />
    ];<br />
    //Load the available tags from database start<br />
    $.ajax({<br />
        type: &#8216;GET&#8217;,<br />
        dataType: &#8216;json&#8217;,<br />
        contentType: &#8216;application/json;charset=utf-8&#8217;,<br />
        url: &#8216;http://localhost:56076/api/Tag&#8217;,<br />
        success: function (data) {<br />
            try {<br />
                if (data.length &gt; 0) {<br />
                    availableTags = data;<br />
                }<br />
            } catch (e) {<br />
                console.log(&#8216;Error while formatting the data : &#8216; + e.message)<br />
            }<br />
        },<br />
        error: function (xhrequest, error, thrownError) {<br />
            console.log(&#8216;Error while ajax call: &#8216; + error)<br />
        }<br />
    });<br />
    //Load the available tags from database end</p>
<p>    $(&quot;#tags&quot;).tagit({<br />
        availableTags: availableTags,<br />
        autocomplete: { delay: 0, minLength: 1 },<br />
        beforeTagAdded: function (event, ui) {<br />
            if ($.inArray(ui.tagLabel, availableTags) &lt; 0) {<br />
                $(&#8216;#error&#8217;).show();<br />
                return false;<br />
            } else {<br />
                $(&#8216;#error&#8217;).hide();<br />
            }<br />
        }<br />
    });<br />
});<br />
[/js]</p>
<p>Now only thing pending is to get the data from our API controller, we will see that part now. For that first you must create a database and a table in it right?</p>
<p><strong>Create a database</strong></p>
<p>The following query can be used to create a database in your SQL Server.</p>
<p>[sql]<br />
USE [master]<br />
GO</p>
<p>/****** Object:  Database [TrialsDB]    Script Date: 17-Feb-16 10:21:17 PM ******/<br />
CREATE DATABASE [TrialsDB]<br />
 CONTAINMENT = NONE<br />
 ON  PRIMARY<br />
( NAME = N&#8217;TrialsDB&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB.mdf&#8217; , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )<br />
 LOG ON<br />
( NAME = N&#8217;TrialsDB_log&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB_log.ldf&#8217; , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET COMPATIBILITY_LEVEL = 110<br />
GO</p>
<p>IF (1 = FULLTEXTSERVICEPROPERTY(&#8216;IsFullTextInstalled&#8217;))<br />
begin<br />
EXEC [TrialsDB].[dbo].[sp_fulltext_database] @action = &#8216;enable&#8217;<br />
end<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULL_DEFAULT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULLS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_PADDING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_WARNINGS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ARITHABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CLOSE OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CREATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_SHRINK OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_CLOSE_ON_COMMIT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_DEFAULT  GLOBAL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CONCAT_NULL_YIELDS_NULL OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET NUMERIC_ROUNDABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET QUOTED_IDENTIFIER OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECURSIVE_TRIGGERS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  DISABLE_BROKER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DATE_CORRELATION_OPTIMIZATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TRUSTWORTHY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ALLOW_SNAPSHOT_ISOLATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PARAMETERIZATION SIMPLE<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET READ_COMMITTED_SNAPSHOT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET HONOR_BROKER_PRIORITY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECOVERY FULL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  MULTI_USER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PAGE_VERIFY CHECKSUM<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DB_CHAINING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TARGET_RECOVERY_TIME = 0 SECONDS<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  READ_WRITE<br />
GO<br />
[/sql]</p>
<p>Now we will create a table 🙂</p>
<p><strong>Create table in database</strong></p>
<p>Below is the query to create table in database.</p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>/****** Object:  Table [dbo].[tblTags]    Script Date: 17-Feb-16 10:22:00 PM ******/<br />
SET ANSI_NULLS ON<br />
GO</p>
<p>SET QUOTED_IDENTIFIER ON<br />
GO</p>
<p>CREATE TABLE [dbo].[tblTags](<br />
	[tagId] [int] IDENTITY(1,1) NOT NULL,<br />
	[tagName] [nvarchar](50) NOT NULL,<br />
	[tagDescription] [nvarchar](max) NULL,<br />
 CONSTRAINT [PK_tblTags] PRIMARY KEY CLUSTERED<br />
(<br />
	[tagId] ASC<br />
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]<br />
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]</p>
<p>GO<br />
[/sql]</p>
<p>Can we insert some data to the table now?</p>
<p><strong>Insert data to table</strong></p>
<p>You can use the below query to insert the data.</p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>INSERT INTO [dbo].[tblTags]<br />
           ([tagName]<br />
           ,[tagDescription])<br />
     VALUES<br />
           (&lt;tagName, nvarchar(50),&gt;<br />
           ,&lt;tagDescription, nvarchar(max),&gt;)<br />
GO<br />
[/sql]</p>
<p>So let us say, we have inserted the data as follows.</p>
<div id="attachment_11248" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631.png"><img decoding="async" aria-describedby="caption-attachment-11248" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631.png" alt="Insertion_In_Table" width="650" height="176" class="size-full wp-image-11248" srcset="/wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631.png 650w, /wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631-300x81.png 300w, /wp-content/uploads/2016/02/Insertion_In_Table-e1455728194631-400x108.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11248" class="wp-caption-text">Insertion_In_Table</p></div>
<p>Next thing we are going to do is creating a ADO.NET Entity Data Model. </p>
<p><strong>Create Entity Data Model</strong></p>
<p>Right click on your model folder and click new, select ADO.NET Entity Data Model. Follow the steps given. Once you have done the processes, you can see the edmx file and other files in your model folder. </p>
<div id="attachment_11249" style="width: 339px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/ADO_NET_Model_Entity.png"><img decoding="async" aria-describedby="caption-attachment-11249" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/ADO_NET_Model_Entity.png" alt="ADO_NET_Model_Entity" width="329" height="207" class="size-full wp-image-11249" srcset="/wp-content/uploads/2016/02/ADO_NET_Model_Entity.png 329w, /wp-content/uploads/2016/02/ADO_NET_Model_Entity-300x189.png 300w" sizes="(max-width: 329px) 100vw, 329px" /></a><p id="caption-attachment-11249" class="wp-caption-text">ADO_NET_Model_Entity</p></div>
<p>Then it is time to go back our Web API controller. Please change the code as below.</p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Data;<br />
using System.Data.Entity;<br />
using System.Data.Entity.Infrastructure;<br />
using System.Linq;<br />
using System.Net;<br />
using System.Net.Http;<br />
using System.Web;<br />
using System.Web.Http;<br />
using Load_Tags_From_DB_Using_Angular_JS_In_MVC.Models;</p>
<p>namespace Load_Tags_From_DB_Using_Angular_JS_In_MVC.Controllers<br />
{<br />
    public class TagController : ApiController<br />
    {<br />
        private DBEntities db = new DBEntities();</p>
<p>        // GET api/Tag<br />
        public IEnumerable&lt;tblTag&gt; Get()<br />
        {<br />
            return db.tblTags.AsEnumerable();<br />
        }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Once this is done, we can say that we are finished with all steps. That&#8217;s fantastic right? Now we will see the output.</p>
<p><strong>Output</strong></p>
<div id="attachment_11250" style="width: 563px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Load_Tags_From_Database_Output.png"><img decoding="async" aria-describedby="caption-attachment-11250" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Load_Tags_From_Database_Output.png" alt="Load_Tags_From_Database_Output" width="553" height="146" class="size-full wp-image-11250" srcset="/wp-content/uploads/2016/02/Load_Tags_From_Database_Output.png 553w, /wp-content/uploads/2016/02/Load_Tags_From_Database_Output-300x79.png 300w, /wp-content/uploads/2016/02/Load_Tags_From_Database_Output-400x106.png 400w" sizes="(max-width: 553px) 100vw, 553px" /></a><p id="caption-attachment-11250" class="wp-caption-text">Load_Tags_From_Database_Output</p></div>
<p>Have a happy coding.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Did you try Web API yet? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/tagit-control-with-data-from-database-using-angular-js-in-mvc-web-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Generate Database Scripts With Data In SQL Server</title>
		<link>https://sibeeshpassion.com/generate-database-scripts-with-data-in-sql-server/</link>
					<comments>https://sibeeshpassion.com/generate-database-scripts-with-data-in-sql-server/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 19 Feb 2016 09:09:51 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Generate Scripts]]></category>
		<category><![CDATA[Scripts With Data]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11270</guid>

					<description><![CDATA[In this post we will discuss about how we can generate SQL Server scripts of our database with existing data, once we generate the script, the result will give you all the insert query with other queries so that the data also will get inserted in your new database. We are going to use the option &#8216;Schema and data&#8217; in SQL server for this task. I hope the screen shots given will help you generate the script with insert queries. Background I was working with an article which has so many database transactions/actions. So I thought of attaching the database [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will discuss about how we can generate SQL Server scripts of our database with existing data, once we generate the script, the result will give you all the insert query with other queries so that the data also will get inserted in your new database. We are going to use the option &#8216;Schema and data&#8217; in SQL server for this task. I hope the screen shots given will help you generate the script with insert queries. </p>
<p><strong>Background</strong></p>
<p>I was working with an article which has so many database transactions/actions. So I thought of attaching the database scripts with data also in the source code download section of the article, so that it may help user to insert the data in his/her database. That made me to write this article. I hope you will like this.</p>
<p><strong>Steps To Generate Database Scripts With Data In SQL Server</strong></p>
<p><strong>Step 1</strong></p>
<p>Right click on your database and select Task -> generate script. </p>
<div id="attachment_11271" style="width: 593px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Option.png"><img decoding="async" aria-describedby="caption-attachment-11271" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Option.png" alt="Database_Scripts_With_Data_Select_Option" width="583" height="586" class="size-full wp-image-11271" srcset="/wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Option.png 583w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Option-150x150.png 150w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Option-298x300.png 298w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Option-130x130.png 130w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Option-400x402.png 400w" sizes="(max-width: 583px) 100vw, 583px" /></a><p id="caption-attachment-11271" class="wp-caption-text">Database_Scripts_With_Data_Select_Option</p></div>
<p><strong>Step 2</strong></p>
<p>Click next in the introduction screen.</p>
<div id="attachment_11272" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Inroduction-e1455872059585.png"><img decoding="async" aria-describedby="caption-attachment-11272" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Inroduction-e1455872059585.png" alt="Database_Scripts_With_Data_Inroduction" width="650" height="604" class="size-full wp-image-11272" srcset="/wp-content/uploads/2016/02/Database_Scripts_With_Data_Inroduction-e1455872059585.png 384w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Inroduction-e1455872059585-300x279.png 300w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Inroduction-e1455872059585-400x372.png 400w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Inroduction-e1455872059585-646x600.png 646w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11272" class="wp-caption-text">Database_Scripts_With_Data_Inroduction</p></div>
<p><strong>Step 3</strong></p>
<p>Select the database object which you are all you need and then click next.</p>
<div id="attachment_11273" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Database_Objects-e1455872190424.png"><img decoding="async" aria-describedby="caption-attachment-11273" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Database_Objects-e1455872190424.png" alt="Database_Scripts_With_Data_Select_Database_Objects" width="650" height="604" class="size-full wp-image-11273" srcset="/wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Database_Objects-e1455872190424.png 384w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Database_Objects-e1455872190424-300x279.png 300w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Database_Objects-e1455872190424-400x372.png 400w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Select_Database_Objects-e1455872190424-646x600.png 646w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11273" class="wp-caption-text">Database_Scripts_With_Data_Select_Database_Objects</p></div>
<p><strong>Step 4</strong></p>
<p>Now you will be shown a window which asks you about how your script should be published. </p>
<div id="attachment_11274" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Publish_Options-e1455872352563.png"><img decoding="async" aria-describedby="caption-attachment-11274" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Publish_Options-e1455872352563.png" alt="Database_Scripts_With_Data_Publish_Options" width="650" height="604" class="size-full wp-image-11274" srcset="/wp-content/uploads/2016/02/Database_Scripts_With_Data_Publish_Options-e1455872352563.png 384w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Publish_Options-e1455872352563-300x279.png 300w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Publish_Options-e1455872352563-400x372.png 400w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Publish_Options-e1455872352563-646x600.png 646w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11274" class="wp-caption-text">Database_Scripts_With_Data_Publish_Options</p></div>
<p>Click advanced in that window. </p>
<p><strong>Step 5</strong></p>
<p>Select &#8216;Schema and data&#8217; from type of data to script option and then click OK. </p>
<div id="attachment_11275" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Advanced-e1455872521896.png"><img decoding="async" aria-describedby="caption-attachment-11275" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Advanced-e1455872521896.png" alt="Database_Scripts_With_Data_Advanced" width="650" height="604" class="size-full wp-image-11275" srcset="/wp-content/uploads/2016/02/Database_Scripts_With_Data_Advanced-e1455872521896.png 384w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Advanced-e1455872521896-300x279.png 300w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Advanced-e1455872521896-400x372.png 400w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Advanced-e1455872521896-646x600.png 646w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11275" class="wp-caption-text">Database_Scripts_With_Data_Advanced</p></div>
<p>Click next.</p>
<p><strong>Step 6</strong></p>
<p>Click finish, now check the script file, it must be having the insert queries too. </p>
<div id="attachment_11276" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Finish-e1455872683355.png"><img decoding="async" aria-describedby="caption-attachment-11276" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Database_Scripts_With_Data_Finish-e1455872683355.png" alt="Database_Scripts_With_Data_Finish" width="650" height="604" class="size-full wp-image-11276" srcset="/wp-content/uploads/2016/02/Database_Scripts_With_Data_Finish-e1455872683355.png 384w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Finish-e1455872683355-300x279.png 300w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Finish-e1455872683355-400x372.png 400w, /wp-content/uploads/2016/02/Database_Scripts_With_Data_Finish-e1455872683355-646x600.png 646w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11276" class="wp-caption-text">Database_Scripts_With_Data_Finish</p></div>
<p>Now what else is pending, go ahead and run your script. </p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/generate-database-scripts-with-data-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Export MDX Result As Excel</title>
		<link>https://sibeeshpassion.com/export-mdx-result-as-excel/</link>
					<comments>https://sibeeshpassion.com/export-mdx-result-as-excel/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 28 Oct 2015 09:10:06 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MDX Query]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[ADOMD]]></category>
		<category><![CDATA[ADOMD CellSet]]></category>
		<category><![CDATA[Export CellSet in MVC]]></category>
		<category><![CDATA[Export In MDX]]></category>
		<category><![CDATA[Export MDX Result As Excel]]></category>
		<category><![CDATA[MDX]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[SSAS]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10841</guid>

					<description><![CDATA[In this post we will see how we can export mdx query result. Here we are going to use MVC with the help of jQuery Ajax. We will run the MDX query and get the cell set and then we will convert this cell set to html table so that we can render this html table easily in client side. Once we render the html table we will do some manipulations with the data, to increase the readability. We use one jQuery Ajax Call, One Controller, One function to execute the query and get cell set, and another function to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will see how we can export mdx query result. Here we are going to use MVC with the help of jQuery Ajax. We will run the MDX query and get the cell set and then we will convert this cell set to html table so that we can render this html table easily in client side. Once we render the html table we will do some manipulations with the data, to increase the readability. We use one jQuery Ajax Call, One Controller, One function to execute the query and get cell set, and another function to convert the cell set to html table. And at last the controller will return the html table to the ajax success. And then we will export the data in client side. Simple right? Then let us move on. I hope you will like this article.</p>
<p>You can always read the about Microsoft ADOMD, MDX Queries and Cell Set here: <a href="http://sibeeshpassion.com/category/microsoft-adomd/" target="_blank" rel="noopener">Microsoft ADOMD,MDX,CellSet</a></p>
<p><strong>Background</strong></p>
<p>Recently I got a requirement to export the MDX query result to Excel. When a user clicks on a button I needed to export the MDX query result of the cube given. Here in this post I am sharing you the process I have done. </p>
<p><strong>Using the code</strong></p>
<p>First of all you need to create a button in your page to fire the click event.</p>
<p>[html]<br />
 &lt;input type=&quot;submit&quot; class=&quot;exprotbutton&quot; value=&quot;Export to Excel&quot; id=&#8217;excelExport&#8217; /&gt;<br />
[/html]</p>
<p>Now you need to load the jQuery reference to the page.</p>
<p>[js]<br />
&lt;script src=&quot;Scripts/jquery-1.11.1.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>The next thing is to fire the click event.</p>
<p>[js]<br />
 $(&#8216;#excelExport&#8217;).bind(&#8216;click&#8217;, function (e) {<br />
        try {<br />
        } catch (e) {<br />
            console.log(&#8216;Excel Export Grid: &#8216; + e.message);<br />
        }<br />
    });<br />
[/js]</p>
<p>Now we will create an ajax call to our controller. </p>
<p>[js]<br />
$.ajax({<br />
                url: &#8216;../Exporting/Export/&#8217;,<br />
                type: &#8216;GET&#8217;,<br />
                dataType: &#8216;json&#8217;,<br />
                contentType: &#8216;application/json; charset=utf-8&#8217;,<br />
                success: function (data) {<br />
                },<br />
                error: function (xhrequest, ErrorText, thrownError) {<br />
                    console.log(&#8216;Excel Export Grid: &#8216; + thrownError);<br />
                }</p>
<p>            });<br />
[/js]</p>
<blockquote><p>Here Exporting is the controller name and Export is the action name</p></blockquote>
<p>Have you noticed that we have not created the action yet. No worries we will create it now.</p>
<p>[csharp]<br />
public JsonResult Export()<br />
        {<br />
            StringBuilder sbConnectionString = new StringBuilder();<br />
            sbConnectionString.Append(&quot;Provider=MSOLAP;data source=&quot;);<br />
            sbConnectionString.Append(serverName + &quot;;initial catalog=&quot; + databaseName + &quot;;Integrated Security=SSPI;Persist Security Info=False;&quot;);</p>
<p>            string readString = myModel.ExCellSet(query, sbConnectionString.ToString());<br />
            return Json(readString, JsonRequestBehavior.AllowGet);<br />
        }<br />
[/csharp]</p>
<blockquote><p> Here serverName, databaseName and query are the global variable I set. You can pass your own here.</p></blockquote>
<p>Now we are passing the query and connection string to our model myModel and fire call the function ExCellSet. This ExCellSet function will execute the query and return the cell set. So shall we create that model function?</p>
<p>[csharp]<br />
 public string ExCellSet(string query, string adoMDConnection)<br />
        {<br />
            string readerString = string.Empty;<br />
            CellSet cst = null;<br />
            AdomdConnection conn = new AdomdConnection(adoMDConnection);<br />
            try<br />
            {<br />
                try<br />
                {<br />
                    conn.Open();<br />
                }<br />
                catch (Exception){<br />
                }</p>
<p>                using (AdomdCommand cmd = new AdomdCommand(query, conn))<br />
                {<br />
                    cmd.CommandTimeout = connectionTimeout;<br />
                    cst = cmd.ExecuteCellSet();<br />
                }<br />
                if (cst.Axes != null)<br />
                {<br />
                    readerString = BuildHTML(cst);<br />
                    return readerString;<br />
                }<br />
                else<br />
                    return null;<br />
            }</p>
<p>            catch (Exception)<br />
            {<br />
                cst = null;<br />
                throw;<br />
            }<br />
            finally<br />
            {<br />
                conn.Close(false);<br />
                cst = null;<br />
            }<br />
        }<br />
[/csharp]</p>
<p>So our cell set is ready now we need to convert this cell set to the HTML table right? For that I strongly recommend you to read here: <a href="http://sibeeshpassion.com/convert-cellset-to-html-table-and-from-html-to-json-to-array/" target="_blank" rel="noopener">Convert CellSet to HTML Table</a></p>
<p>Anyway I am pasting the code here for your reference.</p>
<p>[csharp]</p>
<p>try<br />
            {<br />
                System.Text.StringBuilder result = new System.Text.StringBuilder();<br />
                //check if any axes were returned else throw error.<br />
                int axes_count = cst.Axes.Count;<br />
                if (axes_count == 0)<br />
                    throw new Exception(“No data returned for the selection”);<br />
                //if axes count is not 2<br />
                if (axes_count != 2)<br />
                    throw new Exception(“The sample code support only queries with two axes”);<br />
                //if no position on either row or column throw error<br />
                if (!(cst.Axes[0].Positions.Count &gt; 0) &amp;&amp; !(cst.Axes[1].Positions.Count &gt; 0))<br />
                    throw new Exception(“No data returned for the selection”);<br />
                int cur_row, cur_col, col_count, row_count, col_dim_count, row_dim_count;<br />
                cur_row = cur_col = col_count = row_count = col_dim_count = row_dim_count = 0;<br />
                //Number of dimensions on the column<br />
                col_dim_count = cst.Axes[0].Positions[0].Members.Count;<br />
                //Number of dimensions on the row<br />
                if (cst.Axes[1].Positions[0].Members.Count &gt; 0)<br />
                    row_dim_count = cst.Axes[1].Positions[0].Members.Count;<br />
                //Total rows and columns<br />
                row_count = cst.Axes[1].Positions.Count +<br />
                    col_dim_count;  //number of rows + rows for column headers<br />
                col_count = cst.Axes[0].Positions.Count +<br />
                    row_dim_count;  //number of columns + columns for row headers<br />
                //gridPanel.ClientIDMode = System.Web.UI.ClientIDMode.AutoID;<br />
                //////lets clear any controls under the grid panel<br />
                //gridPanel.Controls.Clear();<br />
                ////Add new server side table control to gridPanel<br />
                Table tblgrid = new Table();<br />
                tblgrid.Attributes.Add(“Id”, “myhtmltab”);<br />
                tblgrid.Attributes.Add(“class”, “display”);<br />
                //We will use label control to add text to the table cell<br />
                Label lbl;<br />
                string previousText = “”;<br />
                int colSpan = 1;<br />
                for (cur_row = 0; cur_row &lt; row_count; cur_row++)<br />
                {<br />
                    //add new row to table<br />
                    TableRow tr = new TableRow();<br />
                    for (cur_col = 0; cur_col &lt; col_count; cur_col++)<br />
                    {<br />
                        //create new cell and instance of label<br />
                        TableCell td = new TableCell();<br />
                        TableHeaderCell th = new TableHeaderCell();<br />
                        lbl = new Label();<br />
                        //check if we are writing to a ROW having column header<br />
                        if (cur_row &lt; col_dim_count)<br />
                        {<br />
                            //check if we are writing to a cell having row header<br />
                            if (cur_col &lt; row_dim_count)<br />
                            {<br />
                                //this should be empty cell — it’s on top left of the grid.<br />
                                //result.Append(” ,”);<br />
                                lbl.Text = ” “;<br />
                                td.CssClass = “titleAllLockedCell”; //this locks<br />
                                    //the cell so it doesn’t scroll upwards nor leftwards<br />
                            }<br />
                            else<br />
                            {<br />
                                //this is a column header cell — use member caption for header<br />
                                //result.Append(cst.Axes[0].Positions[cur_col –<br />
                                //    row_dim_count].Members[cur_row].Caption + “,”);<br />
                                //if (cur_row &lt; 1)<br />
                                //{<br />
                                    lbl.Text = cst.Axes[0].Positions[cur_col – row_dim_count].Members[cur_row].Caption;<br />
                                    th.CssClass = “titleTopLockedCell”; // this lockeders<br />
                                            //the cell so it doesn’t scroll upwards<br />
                                //}<br />
                                if (lbl.Text == previousText)<br />
                                {<br />
                                    colSpan++;<br />
                                }<br />
                                else<br />
                                {<br />
                                    colSpan = 1;<br />
                                }<br />
                            }<br />
                        }<br />
                        else<br />
                        {<br />
                            //We are here.. so we are writing a row having data (not column headers)<br />
                            //check if we are writing to a cell having row header<br />
                            if (cur_col &lt; row_dim_count)<br />
                            {<br />
                                //this is a row header cell — use member caption for header<br />
                                lbl.Text = cst.Axes[1].Positions[cur_row –<br />
                                col_dim_count].Members[cur_col].Caption.Replace(“,”, ” “);<br />
                                td.CssClass = “titleLeftLockedCell”; // this lockeders<br />
                                    //the cell so it doesn’t scroll leftwards<br />
                            }<br />
                            else<br />
                            {<br />
                                //this is data cell.. so we write the Formatted value of the cell.<br />
                                lbl.Text = cst[cur_col – row_dim_count, cur_row – col_dim_count].FormattedValue;<br />
                                //td.InnerText = cst[cur_col – row_dim_count,<br />
                                //cur_row – col_dim_count].FormattedValue;<br />
                                td.CssClass = “valueCell”; //this  right<br />
                                        //aligns the values in the column<br />
                            }<br />
                            //turn the wrapping off for row header and data cells.<br />
                            td.Wrap = true;<br />
                        }<br />
                        if (((lbl.Text != previousText) || (lbl.Text == ” “))<br />
                            &amp;&amp; (cur_row &lt; col_dim_count))<br />
                        {<br />
                            tr.TableSection = TableRowSection.TableHeader;<br />
                            th.Text = “HEADER”;<br />
                            th.Controls.Add(lbl);<br />
                            tr.Cells.Add(th);<br />
                            tblgrid.Rows.Add(tr);<br />
                        }<br />
                        else if ((lbl.Text != previousText) || (lbl.Text == ” “) ||<br />
                            (lbl.Text == null) || (lbl.Text == “”))<br />
                        {<br />
                            td.Controls.Add(lbl);<br />
                            tr.Cells.Add(td);<br />
                            tblgrid.Rows.Add(tr);<br />
                        }<br />
                        else<br />
                        {<br />
                            try<br />
                            {<br />
                                tr.Cells[tr.Cells.Count – 1].ColumnSpan = colSpan;<br />
                            }<br />
                            catch<br />
                            {<br />
                            }<br />
                        }<br />
                        if (cur_row &lt; col_dim_count)<br />
                            previousText = lbl.Text;<br />
                    }<br />
                    //result.AppendLine();<br />
                }<br />
                using (StringWriter writer = new StringWriter())<br />
                {<br />
                    HtmlTextWriter htw = new HtmlTextWriter(writer);<br />
                    tblgrid.RenderControl(htw);<br />
                    return htw.InnerWriter.ToString();<br />
                }<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                throw ex;<br />
            }<br />
[/csharp]</p>
<p>So it seems everything is set, now we have our html table, the controller will return this string to json, do you remember we have given the type as json in our ajax call?</p>
<p>[csharp]<br />
 return Json(readString, JsonRequestBehavior.AllowGet);<br />
[/csharp]</p>
<p>Since our data is ready, we will re write our ajax function as follows.</p>
<p>[js]<br />
  $(&#8216;#excelExport&#8217;).bind(&#8216;click&#8217;, function (e) {<br />
        try {<br />
            $.ajax({<br />
                url: &#8216;../Exporting/Export/&#8217;,<br />
                type: &#8216;GET&#8217;,<br />
                dataType: &#8216;json&#8217;,<br />
                contentType: &#8216;application/json; charset=utf-8&#8217;,<br />
                success: function (data) {<br />
                    data = &#8216;&lt;div&gt;&#8217; + data + &#8216;&lt;/div&gt;&#8217;;<br />
                    var updateHtmlDom = $.parseHTML(data);<br />
                    var AppliedHtml = updateHtmlDom[0].innerHTML;<br />
                    AppliedHtml = tableToExcel(AppliedHtml, title + &quot;.xls&quot;);<br />
                    saveText($(&#8216;#SubmitForm&#8217;), title + &quot;.xls&quot;, AppliedHtml, &#8216;text/xls;charset=utf-8&#8217;);<br />
                },<br />
                error: function (xhrequest, ErrorText, thrownError) {<br />
                    console.log(&#8216;Excel Export Grid: &#8216; + thrownError);<br />
                }</p>
<p>            });<br />
        } catch (e) {<br />
            console.log(&#8216;Excel Export Grid: &#8216; + e.message);<br />
        }<br />
    });<br />
[/js]</p>
<p>The first step we are doing is parsing the html we got by using $.parseHTML in jQuery. Next we are passing the parsed data to the the function tableToExcel so that the table can be formatted in the format of excel data. Here is the code for the function tableToExcel.</p>
<p>[js]<br />
var tableToExcel = (function (table) {<br />
    var uri = &#8216;data:application/vnd.ms-excel;base64,&#8217;<br />
, template = &#8216;&lt;html xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot; xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot; xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;&lt;head&gt;&lt;!&#8211;[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:Name&gt;{worksheet}&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:DisplayGridlines /&gt;&lt;/x:WorksheetOptions&gt;&lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]&#8211;&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;{table}&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;&#8217;<br />
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }<br />
    , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }<br />
    return function (table, name) {<br />
        var length = name.replace(&#8216;.xls&#8217;, &#8221;).length;<br />
        if (length &gt; 30) {<br />
            name = name.slice(0, 25) + &#8216;&#8230;&#8217;;<br />
        }<br />
        else<br />
            name.replace(&#8216;.xls&#8217;, &#8221;);<br />
        var ctx = { worksheet: name || &#8216;Worksheet&#8217;, table: table }<br />
        return format(template, ctx)<br />
    }<br />
})()<br />
[/js]</p>
<p>Now we have formatted the html data to the one which excel supports. We are passing the data to the function saveText as follows.</p>
<p>[js]<br />
saveText($(&#8216;#SubmitForm&#8217;), title + &quot;.xls&quot;, AppliedHtml, &#8216;text/xls;charset=utf-8&#8217;);<br />
[/js]</p>
<p>Here title is the file name of the excel file to generated. The below is the definition of saveText function.</p>
<p>[js]<br />
function saveText(ref, fname, text, mime) {<br />
    var blob = new Blob([text], { type: mime });<br />
    saveAs(blob, fname);<br />
    return false;<br />
}<br />
[/js]</p>
<p>Next we are going to export the data using blob export technology in HTML5. </p>
<blockquote><p>If you are new to blog, you can check here <a href="http://sibeeshpassion.com/compress-xml-string-variables-in-client-side-and-export-in-html5-using-jquery/" target="_blank" rel="noopener">Using blob</a> to understand how to use it.
</p></blockquote>
<p>Everything is set now. Build your application and check the output now. Just click on the export button, I am sure an excel file will be downloaded.</p>
<blockquote><p>
The time taken for the exporting is completely depends on how many data your query returns. I suggest you to export maximum of 5000 for a query, so that it won&#8217;t affect any other process.
</p></blockquote>
<div id="attachment_10843" style="width: 332px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/Excel_Export_In_MDX.png"><img decoding="async" aria-describedby="caption-attachment-10843" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/Excel_Export_In_MDX.png" alt="Excel Export In MDX" width="322" height="251" class="size-full wp-image-10843" srcset="/wp-content/uploads/2015/10/Excel_Export_In_MDX.png 322w, /wp-content/uploads/2015/10/Excel_Export_In_MDX-300x234.png 300w" sizes="(max-width: 322px) 100vw, 322px" /></a><p id="caption-attachment-10843" class="wp-caption-text">Excel Export In MDX</p></div>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/export-mdx-result-as-excel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Interview Questions And Answers</title>
		<link>https://sibeeshpassion.com/sql-interview-questions-and-answers/</link>
					<comments>https://sibeeshpassion.com/sql-interview-questions-and-answers/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sat, 24 Oct 2015 06:38:39 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Interview]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Career Advice]]></category>
		<category><![CDATA[SQL Interview Questions And Answers]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10834</guid>

					<description><![CDATA[In this article we will discuss about the most asked SQL interview questions and answers. If you need to know other interview questions and answers, I strongly recommend to follow this link: Interview Questions. Now in this post we are going to share the interview questions or the information which you must know as a programmer or a developer, especially if you are a Dot Net developer. We will explain few questions here, if you still need some additional information on SQL, you can read here: SQL . I hope you will like this article. Background I am a dot [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we will discuss about the most asked <a href="http://sibeeshpassion.com/category/sql/" target="_blank">SQL </a>interview questions and answers. If you need to know other interview questions and answers, I strongly recommend to follow this link: <a href="http://sibeeshpassion.com/category/interview/" target="_blank">Interview Questions</a>. Now in this post we are going to share the interview questions or the information which you must know as a programmer or a developer, especially if you are a Dot Net developer. We will explain few questions here, if you still need some additional information on SQL, you can read here: <a href="http://sibeeshpassion.com/category/sql/" target="_blank">SQL </a>. I hope you will like this article.</p>
<p><strong>Background</strong></p>
<p>I am a dot net developer. As a dot net developer, there are so many things that I must be aware of. I am sharing those in the form of articles, you can always read my other interview questions here in the below links.</p>
<li><a href="http://sibeeshpassion.com/dot-net-interview-questions-for-experienced-and-fresher/" target="_blank">Interview Questions For Experienced and Beginner .NET Professionals</a></li>
<li><a href="http://sibeeshpassion.com/infosys-interview-questions-for-dotnet-professionals/" target="_blank">Infosys Interview Questions For DotNet Professionals</a></li>
<p>So shall we now discuss about SQL interview questions?</p>
<p><strong>SQL Interview Questions</strong></p>
<p><strong>What are the types of Joins in SQL? Explain?</strong></p>
<li>INNER JOIN</li>
<p>Returns all rows when there is at least one match in BOTH tables </p>
<li>LEFT JOIN</li>
<p>Return all rows from the left table, and the matched rows from the right table </p>
<li>RIGHT JOIN</li>
<p>Return all rows from the right table, and the matched rows from the left table </p>
<li>FULL JOIN</li>
<p>Return all rows when there is a match in ONE of the tables </p>
<p><strong>What is the default join in SQL? Give an example query?</strong></p>
<p>The default join is INNER JOIN. </p>
<p>Example: </p>
<p>[sql]<br />
SELECT column_name(s)<br />
FROM table1<br />
INNER JOIN table2<br />
ON table1.column_name=table2.column_name;<br />
[/sql]</p>
<p><strong>Describe all the joins with examples in SQL?</strong></p>
<p><em>SQL LEFT JOIN </em></p>
<p>The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match. </p>
<p>[sql]<br />
SQL LEFT JOIN Syntax<br />
SELECT column_name(s)<br />
FROM table1<br />
LEFT JOIN table2<br />
ON table1.column_name=table2.column_name;<br />
[/sql]</p>
<p><em>SQL RIGHT JOIN </em></p>
<p>The right join returns all the rows in the right table ie table 2 with the matching ones in the left table(table1). </p>
<p>[sql]<br />
SELECT column_name(s)<br />
FROM table1<br />
RIGHT JOIN table2<br />
ON table1.column_name=table2.column_name;<br />
[/sql]</p>
<p><em>SQL FULL OUTER </em></p>
<p>The full join returns all rows from the left table (table1) and from the right table (table2) </p>
<p>[sql]<br />
SELECT column_name(s)<br />
FROM table1<br />
FULL OUTER JOIN table2<br />
ON table1.column_name=table2.column_name;<br />
[/sql]</p>
<p><strong>What is Union And Union All ? Explain the differences?</strong></p>
<p><em>SQL UNION  </em></p>
<p>The UNION operator is used to combine the result-set of two or more SELECT statements. </p>
<p>Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order. </p>
<blockquote><p>Note: The UNION operator selects only distinct values by default.  </p></blockquote>
<p>[sql]<br />
SELECT column_name(s) FROM table1<br />
UNION<br />
SELECT column_name(s) FROM table2;<br />
[/sql]</p>
<p><em>SQL UNION ALL</em> </p>
<p>[sql]<br />
SQL UNION ALL Syntax<br />
SELECT column_name(s) FROM table1<br />
UNION ALL<br />
SELECT column_name(s) FROM table2;<br />
[/sql]</p>
<blockquote><p>Allows duplicate values. </p></blockquote>
<p><strong>Differentiate Clustered and Non clustered Index in SQL?</strong></p>
<p>A clustered index is one in which the index&#8217;s order is arranged according to the physical order of rows in the table. Due to this reason there can only be one clustered index per table, usually this is the primary key. </p>
<p>A non clustered index is one in which the order of index is not in accordance with the physical order of rows in the table. </p>
<p><em>Create Index Syntax </em></p>
<p>[sql]<br />
CREATE INDEX [ CLUSTERED | NONCLUSTERED ] PIndex ON Persons (LastName,FirstName)<br />
[/sql]</p>
<p><strong>Explain the difference between Stored Procedure and User Defined Function?</strong></p>
<p><em>Stored Procedure </em></p>
<p>Stored procedures are reusable code in database which is compiled for first time and its execution plan saved. The compiled code is executed when everytime its called. You  </p>
<p><em>Function </em></p>
<p>Function is a database object in SQL Server. Basically it is a set of SQL statements that accepts only input parameters, perform actions and return the result. Function can return only single value or a table. We can’t use function to Insert, Update, Delete records in the database table(s). It is compiled eveyrtime its invoked.  </p>
<p><em>Basic Difference </em></p>
<p>Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).<br />
Functions can have only input parameters for it whereas Procedures can have input/output parameters .<br />
Functions can be called from Procedure whereas Procedures cannot be called from Function </p>
<p><em>Advanced Difference </em></p>
<p>Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.<br />
Procedures cannot be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.<br />
Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.<br />
The most important feature of stored procedures over function is to retention and reuse the execution plan while in case of function it will be compiled every time. </p>
<p>Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.<br />
Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.<br />
Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.<br />
We can use transactions in stored procedure but not in functions.  </p>
<p>That&#8217;s all. Have a great day.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/sql-interview-questions-and-answers/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
	</channel>
</rss>
