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.
| Author |
Topic |
|
kingstonr
Starting Member
3 Posts |
Posted - 2008-06-05 : 12:21:48
|
| select id,qty into #lastyrend from table where dt='12/31/2007'--last yr endselect id, qty into #lastmonthend from table where dt='05/31/2008' --last month end select id, qty into #lastqtrend from table where dt='03/31/2008'--last qtr endselect id,qty into #lastweeked from table where dt='05/27/2008'select id,#lastyrend .qty,case when #lastmonthend.qty is null then #lastyrend .qty as lastmonthendcase when #lastmonthend.qty is null then #lastyrend .qty when #lastqtrend .qty is null then #lastmonthend.qty .qty else #lastqtrend .qty as lastqtrcase when #lastmonthend.qty is null then #lastyrend .qty when #lastqtrend .qty is null then #lastmonthend.qty when #lastweeked .qty is null then #lastqtrend .qty else #lastweeked .qty as lastweekend.from tableleft join table.id=#lastyrend .idleft join table.id=#lastmonthend.idleft join table.id=#lastqtrend.idleft join table.id=#lastweeked.idIN my query I am taking values from a table for different date series.logic is if there is no value for a particular date then take the previous date value.Problem--------------in my query #lastqtrend .qty is null but #lastweeked .qty has the value.as per my third case statement I expected I will take the #lastweeked .qtybut since #lastqtrend .qty is null it shows the value of #lastmonthend.qtyI think here after the case when #lastmonthend.qty is null then #lastyrend .qty when #lastqtrend .qty is null then #lastmonthend.qty ---- after executing this line below line is not executing when #lastweeked .qty is null then #lastqtrend .qty elseCan somebody help me how to execute this. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-05 : 12:31:48
|
[code]from tableleft join #lastyrend on table.id = #lastyrend.idleft join #lastmonthend on table.id = #lastmonthend.idleft join #lastqtrend on table.id = #lastqtrend.idleft join #lastweeked on table.id = #lastweeked.id[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|