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
 General SQL Server Forums
 New to SQL Server Programming
 Create a max for a int field

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 usage
FROM (M3DJDPRD.MVXJDTA.MITBAL INNER JOIN M3DJDPRD.MVXJDTA.MITMAS ON MITBAL.MBITNO=MITMAS.MMITNO) INNER JOIN M3DJDPRD.MVXJDTA.MITSTA
ON MITMAS.MMITNO=MITSTA.MHITNO
WHERE MITSTA.MHCYP6 between 201026 and 201042 AND MITBAL.MBSSQT>=1 and (MITSTA.MHUSQT+MITSTA.MHSOQT) <= 0
ORDER BY MITMAS.MMITNO


My 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.aspx

If you have Date columns, you can use date math to do that. Something like:
SELECT DATEADD(QUARTER, DATEDIFF(QUARTER, 0, CURRENT_TIMESTAMP) - 2, 0)
Go to Top of Page
   

- Advertisement -