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 / soorai ganesh

Hi dude, If u use SQLSERVER 2005 this will help u.......
-------------------------------------------------------

Create table student (studName varchar(50), doj smalldatetime)
insert into student values('Ganesh','05/26/2008')
insert into student values('Ramesh','03/26/2008')
insert into student values('Dinesh','03/26/2008')
insert into student values('Suresh','04/26/2008')

Select * from student

SELECT 'Students Admission by Monthwise',[3] AS March,[4] AS April,[5] AS May
FROM(
SELECT studName,
Month(doj) monthname
FROM student
) A
PIVOT
(
COUNT(studname)
FOR monthname in
([3],[4],[5])
) AS PVT

Is This Answer Correct ?    12 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are sp_configure commands and set commands?

721


What is difference between rownum and row_number?

695


What is difference between index seek vs. Index scan?

819


In what version of sql server were synonyms released?

694


What is the difference between insensitive and scroll cursor?

758






what is the primary use of the model database? : Sql server administration

727


What happens if you are trying to access a schema not owned by you?

719


Explain what are the events recorded in a transaction log?

737


How to query multiple tables jointly?

709


How do you delete duplicate rows in sql server?

661


What are the purposes of floor and sign functions?

731


What do you mean by stored techniques? How would we use it?

766


While you are inserting values into a table with the insert into .. Values option, does the order of the columns in the insert statement have to be the same as the order of the columns in the table?

783


What is shrink log file?

653


What are magic tables in sql server?

788