Category Archives: SQL Server 2008

Drill Down SQL Query

SQL Server does not provide any drill down queries such as Category > Sub Category. There are reporting tools for it but it cannot be done in SQL Query alone without help from theird party software. There is SQL Group … Continue reading

Posted in SQL Server 2008 | Leave a comment

How to give names to group sets in SQL

You have a group set query in SQL that you are using to give sum total of certain numbers. The problem is where the row calculates the sum total, the cell values in the corresponding colums say ‘NULL’. How to … Continue reading

Posted in SQL Server 2008 | Tagged , | Leave a comment

The type of column “xxx” conflicts with the type of other columns specified in the UNPIVOT list.

When pivoting data in SQL Server, all columns must be of same time, otherwise you will get this error. You might get this error if you have imperfect case statement or one column is of integer type while the other … Continue reading

Posted in SQL Server 2008 | Tagged , | Leave a comment

SQL Server PIVOT tutorial

Pivot can be a little tricky to use. I will explain with the help of example — Create Table First create table student( id int not null primary key identity, rno int not null, subject varchar(30), score int, outof int) … Continue reading

Posted in SQL Server 2008 | Tagged , , | Leave a comment

Get No of Sundays in a month SQL Server

The following stored procedure returns number of sundays in given month. It takes date as parameter. Month and year is extract from the date. CREATE FUNCTION GetSundays (@giveDate DATETIME) RETURNS INT AS BEGIN DECLARE @firstday DATETIME, @lastday DATETIME SELECT @firstday … Continue reading

Posted in SQL Server 2008 | Tagged , | Leave a comment

SQL Condition in WHERE Clause

How would you set a condition in where clause in SQL Server? For example you have a parameter @ProjectID. If @ProjectID is 1, then select all employee with EmployeeNo 1000. If @ProjectID=2 then select all employee with employeeNo betweeen 1000 … Continue reading

Posted in SQL Server 2008 | Tagged , | Leave a comment

Add a linked Server in SSMS

I was having issue with running a linked server query and getting the following error Msg 11529, Level 16, State 1, Procedure sp_describe_first_result_set, Line 1 The metadata could not be determined because every code path results in an error; see … Continue reading

Posted in SQL Server 2008, Tutorials/Tips | Tagged , | Leave a comment