| Author |
Topic |
|
learntsql
524 Posts |
Posted - 2009-09-02 : 06:46:33
|
| Hi All,I have input dropdown where it contains all my datecolumn names of my table and year as another input and Areas as another input;If i select any year,Area and any date column i have to show sales as per month wise of that year and Area and sum of salesas likeArea--sales--Monthabc --1000--2abc --2000--3cde --233-- 5def --333-- 9.........here MonthNo is extracted from the column of my table which i selected as date input field(which contains all datetime datatype columns).how can we do this?any sugestions please. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-02 : 06:54:47
|
table structuresample datawanted outputwould help to help! No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-02 : 07:39:33
|
| assume my sample data as ID Area sales(Rs) date1 date2 date3....1 abc 10000 d1 d2 d32 abc 20000 d2 d3 d33 cde 30000 d1 d1 d1..........as i told my input dropdown contains date1,date2,date3 ...(datetime) columns as valueswhen i select any value let say date2 and year input as some year then i have to get all the details from columns considering Area,Sales and Date2 columnsi.e i need to ignore all other datetime columns.my output should like asArea-SumofSales-MonthNameabc-10000-month(d2)abc-20000-month(d3)abc-30000-month(d1) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-02 : 08:30:51
|
| does date field contain full date values or just month and day? |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-02 : 08:33:29
|
| it contains full datetime value. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-02 : 08:36:07
|
| then what's significance of year input? |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-02 : 08:41:17
|
| i have to show sales to selected year. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-02 : 08:49:28
|
| sorry didnt get that. can you illustrate? |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-02 : 09:20:13
|
| sorry i think i am not clear.i have year dropdown.i have to show sales for selected year asi need to filter it in where clause likewhere year(date2)=@iYear --date2 is the value which i selected from datevalues dropdown.if i select date1 then my where condition should change aswhere year(date1)=@iYear....and in my select clause i have to displayArea,Sales,MonthNo.sorry if i am not clear. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-02 : 09:30:12
|
ok for that do like thisSELECT Area,Sales,MonthNoFROM YourTABLEwhere CASE @DateField WHEN 'Date1' THEN DATEADD(dd,DATEDIFF(dd,0,date1),0) WHEN 'Date2' THEN DATEADD(dd,DATEDIFF(dd,0,date2),0) ... END >=DATEADD(yy,@iYear-1900,0) AND CASE @DateField WHEN 'Date1' THEN DATEADD(dd,DATEDIFF(dd,0,date1),0) WHEN 'Date2' THEN DATEADD(dd,DATEDIFF(dd,0,date2),0) ... END< DATEADD(yy,@iYear-1899,0) |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-02 : 09:34:21
|
| Thanks visakh i will try. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-02 : 09:46:01
|
| good luck |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-04 : 01:09:08
|
| sorry for delay reply visakh,MonthNo i have to pick from the column of my table which i pass as date parameter and i need to sum the sales for coresponding months.for eg; if i pass date2 as parameter then the monthno should pick from the column date2 of my table similerly if i pass any other parameter then same as above.at a time i pass only single date parameter. |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-04 : 04:25:32
|
| PLEASE COULD ANYONE REPLY.OR ANY SUGESTIONS OR ANY ALTERNATIVE WAY. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-04 : 04:48:45
|
Like this (using Visakh's approach):selectArea,sum(Sales) as Sales,MonthNofrom( SELECT Area, Sales, case @Datefield when 'Date1' then month(Date1) when 'Date2' then month(Date2) ... end as MonthNo FROM YourTABLE where CASE @DateField WHEN 'Date1' THEN DATEADD(dd,DATEDIFF(dd,0,date1),0) WHEN 'Date2' THEN DATEADD(dd,DATEDIFF(dd,0,date2),0) ... END >=DATEADD(yy,@iYear-1900,0) AND CASE @DateField WHEN 'Date1' THEN DATEADD(dd,DATEDIFF(dd,0,date1),0) WHEN 'Date2' THEN DATEADD(dd,DATEDIFF(dd,0,date2),0) ... END< DATEADD(yy,@iYear-1899,0))dtgroup by Area,MonthNo No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
learntsql
524 Posts |
Posted - 2009-09-04 : 05:04:52
|
| ThankQ Visakh and Webfred it worked. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-04 : 05:15:50
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|