Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
  Selecting values from table based on the date

Author  Topic 

rajasri
Starting Member

1 Post

Posted - 2011-09-05 : 07:52:41
Hi All,

My table contains UserName, Date, Count.

UserName Date Count

Test 01-08-2011 1
Test 01-08-2011 2
Test 02-08-2011 1
Test 03-08-2011 5

I need to select the values based on the date with group by UserName and date.
Eg:

UserName 1 2 3 .....31

Test 3 1 5 ......

Here 1,2,3 .... indicates date.
2 1 1 ...... indicates count

Can anyone tell me the query for this.

Thanks in advance.
Rajasri.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-05 : 08:16:13
have a look at PIVOT statement below

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -