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 |
|
bartbart
Starting Member
3 Posts |
Posted - 2010-11-15 : 14:23:33
|
| I am trying to create a query that will use a range to pull the data.In doing the my field is an integer field (int). The int field is used as a time/period field (2010 = year and 26 = the 26th week) which means I have a maximum number I can use in this field (ie "52"). Can you tell me how to make this field have a max and then cross over into the previous year?I am currently like so:SELECT MITMAS.MMITNO, MITBAL.MBODDT, MITBAL.MBSSQT, MITSTA.MHUSQT, MITSTA.MHSOQT, MITSTA.MHCYP6,(MITSTA.MHUSQT+MITSTA.MHSOQT) as usageFROM (M3DJDPRD.MVXJDTA.MITBAL INNER JOIN M3DJDPRD.MVXJDTA.MITMAS ON MITBAL.MBITNO=MITMAS.MMITNO) INNER JOIN M3DJDPRD.MVXJDTA.MITSTAON MITMAS.MMITNO=MITSTA.MHITNOWHERE MITSTA.MHCYP6 between 201026 and 201042 AND MITBAL.MBSSQT>=1 and (MITSTA.MHUSQT+MITSTA.MHSOQT) <= 0ORDER BY MITMAS.MMITNOMy Ultimate goal is to have a report run automatically every qtr with the date from current period back two qtrs. |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-11-15 : 17:25:18
|
| If you want to provide DDL, DML and expected output, we can probably help you more. Here is a link for how to post that:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxIf you have Date columns, you can use date math to do that. Something like:SELECT DATEADD(QUARTER, DATEDIFF(QUARTER, 0, CURRENT_TIMESTAMP) - 2, 0) |
 |
|
|
|
|
|
|
|