Table student containing 2 columns,Join date,Employee name.
Under join date 4 rows r ter =1-jan-2008,2-feb-2008,3-mar-
2008,4-feb-2008.Under Employee name 4 difeerent names
jaison,robin,binoy,rahul

Result set is,
Table containing 4-column name=jan,feb,mar,april,,beneath
these months count is given as 1,2,1,0 means these counts
representing number of emplooyees joined in a month(january
1employee,february 2 employee,march 1 employee,april 0
employee)

Can you give me the required sql query

Answer Posted / prg

SELECT Sum([1]) AS Jan, Sum([2]) AS Feb, Sum([3]) AS Mar,Sum([4]) as Apr,Sum([5]) as May,Sum([6]) as Jun,

Sum([7]) as Jul,Sum([8]) as Aug,Sum([9]) as Sep,Sum([10]) as Oct,Sum([11]) as Nov,Sum([12]) as Dec

FROM (SELECT Month(JoinDate) as Mon

FROM AAA) ps

PIVOT

(Count(Mon) FOR Mon IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) AS pvt

group by [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you give me some DBCC command options?(Database consistency check) - DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.

2231


How to create function without parameter in sql server?

738


What is data source document?

755


What is the difference between varchar and varchar(max) datatypes?

762


How to select all columns of all rows from a table with a select statement in ms sql server?

748






What is buffer cash and log cache in sql server?

799


How many triggers you can have on a table?

700


Determine how to use the inserted and deleted pseudo tables?

727


What is the command to change the recovery model?

762


What are the types of lock supported by ?

783


How do database indexes work?

721


What is bcnf normalization form?

847


Can you explain what are various ways to enhance the ssrs report?

767


Differentiate between sql temp table vs table variable?

667


If a stored procedure is taking a table data type, how it looks?

6094