IRohitable | .NET, SQL Server, Ruby on Rails and everything related to Software

What makes a CTE different from a Derived Table/Subquery? When to use it?

by Rohit 23. November 2013 23:30

Common Table Expression (CTE) was introduced in SQL Server 2005. A CTE is a temporary result set similar to a derived table which is not stored as an object. This result set lasts only for the duration of the query. You can reference a CTE within a SELECT, INSERT, UPDATE or DELETE statement.

 

 

Example of a Derived Table:

 

Select EmpId, EmpName, Manager 
From 
(
	select 
	  A.EmployeeId AS EmpId
	, A.EmployeeName AS EmpName
	, B.Manager AS Manager
	from EmployeeMaster A
	inner join EmployeeDetails B
	on A.EmployeeId = B.EmployeeId
	group by A.EmployeeId, A.EmployeeName, B.Manager

) EmployeeInfo

 

Example of a CTE:

 

With EmployeeInfo (EmpId, EmpName, Manager)
As
(
	select 
	  A.EmployeeId AS EmpId
	, A.EmployeeName AS EmpName
	, B.Manager AS Manager
	from EmployeeMaster A
	inner join EmployeeDetails B
	on A.EmployeeId = B.EmployeeId
	group by A.EmployeeId, A.EmployeeName, B.Manager
)
select * from EmployeeInfo

 

 

So what makes CTE different from a derived table? A CTE has few advantages over a derived table: More...

Tags: , , ,

SQL Server | Technology

SQL Server Day Photos - October 26 2013, Microsoft Bangalore

by Rohit 26. October 2013 11:41

Like US, in India we don't have that many communities and live events. When I moved to Bangalore an year back, I searched for .NET and SQL Server user groups in Bangalore. Few .NET user groups exist but not active enough. I came across SQL Server Geeks from a colleague and attended few sessions of SQL Server Day in Bangalore. It is a great initiative by SQL Server Geeks.

 

 

Tags: ,

Blog | Life | SQL Server

Creating Organization Hierarchy in ASP.NET using Google Organizational Chart

by Rohit 8. June 2013 14:48

Google Charts is a collection of wide variety of charts that are exposed as a Javascript library that you just need to embed in your web page. From simple line charts to complex hierarchical tree, the library provides a large number of ready-to-use chart types.

The most common way to use Google Charts is by referencing the Javascript API in your web page. All chart types are populated with data using the DataTable class, making it easy to switch between chart types.

In this post I will show you how to create Organization Hierarchy using Google Visualization API Organizational Chart. Instead of showing how to create the hierarchy using static data, I will show you how to populate DataTable dynamically using SQL Server and C# and later passing this DataTable as JSON object to Google Chart to generate the hierarchy.

To start with let us add a Web Form in our ASP.NET solution. More...

Tags: , ,

ASP.NET | Google Charts | Technology

About Rohit Prakash

Software Craftsman @ Fortune 100 Company. Technical Reviewer of few programming books.

A Single, Writer, Reader and Adventurist.

You can reach me at:

rohit [at] irohitable.com

-----------------------------------------

LinkedIn:

in.linkedin.com/in/rohitpkhare

Twitter:

@BuzzRohit

-----------------------------------------

Month List

Protected by Copyscape Web Plagiarism Software