Author |
Topic |
skillilea
Starting Member
15 Posts |
Posted - 2012-03-22 : 17:53:18
|
what is the best way to get the date in columns.Data is in rows by dateThe values are in dentervalueThey have a QID (question ID)There is one entry for each question for each month so there are 24 records total that I want to show in 12 rows of data return.I am looking to return the values this wayDate QID(1) QID(2)JanFebMar...Here is what I haveSELECT dEnterDate , CASE WHEN qID = 39 THEN dEnterValue END , CASE WHEN qID = 74 THEN dEnterValue END FROM tblQuestion_DataWHERE qid IN(39,74) AND entityID = 23 AND dEnterDate >= '3-1-2011' AND dEnterDate <= '3-1-2012'GROUP BY denterdate, dentervalue, qid |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2012-03-22 : 19:39:57
|
I can't quite follow what you want. Perhaps if you suppied the table definitions, some data and desired output it would clarify the issue.=================================================It is not so much our friends' help that helps us as the confident knowledge that they will help us. -Epicurus, philosopher (c. 341-270 BCE) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-22 : 21:21:04
|
[code]SELECTDATENAME(mm,denterdate), COUNT(QID) FROM tblQuestion_DataWHERE qid IN(39,74)AND entityID = 23AND dEnterDate >= '3-1-2011' AND dEnterDate <= '3-1-2012'GROUP BY DATENAME(mm,denterdate) [/code]??------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
skillilea
Starting Member
15 Posts |
Posted - 2012-03-23 : 05:48:10
|
Thanks for the response.Data looks like this:DATE QID VALUE3/1/2011 39 104/1/2011 39 115/1/2011 39 86/1/2011 39 663/1/2011 74 454/1/2011 74 545/1/2011 74 336/1/2011 74 55I am trying to graph the data by month and need the return this way.DATE QID(39) VALUES QID(74) VALUES3/1/2011 10 454/1/2011 11 545/1/2011 8 336/1/2011 66 55thanks for the help |
 |
|
skillilea
Starting Member
15 Posts |
Posted - 2012-03-25 : 11:30:51
|
Any thoughts on best approach?tnx |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-03-25 : 12:26:06
|
[code]SELECT *FROM YourTablePIVOT(MAX(Value) FOR QID IN ([39],[74]))P[/code] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
skillilea
Starting Member
15 Posts |
Posted - 2012-03-26 : 20:58:13
|
Yep they are static in this case. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-27 : 12:13:15
|
then you're good to go with Sunita's suggestion------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|