Re: Query-Question with 4Y2M
Posted in 1998
On Tue, 13 Oct 1998 Jonathan Leffler wrote: > > On Tue, 13 Oct 1998 andy@pneu.com wrote: > >I search for a way in sql to get an output year and month like > >that: yyyymm where mm must have an leading zero for months < 10. > >column-type is date. > > > >My idea: select YEAR(today) && MONTH(today) from anytable > >does not work, the zero is missing..... > >In ace and 4gl, i would use "using....", but in sql? > >Any Ideas (without changing any DBDATE-settings) ? > > Someone else asked a minor variant on this question not so very long ago. > The answer is simple: > > SELECT YEAR(today) * 100 + MONTH(today) AS yyyymm > FROM AnyTable > > It gives you a 6-digit integer, just as you wanted. You might want to have > a stored procedure to do the job rather than write the expression out many > times: Any way to get a mmdd format via SQL when the month # < 10? SELECT MONTH(today - 13) * 100 + DAY(today - 13) AS mmdd FROM systables where tabid = 1; Result: mmdd 930 -- ______________________________________________________________________ | Colin McGrath cmm@trac3000.ueci.com | | Raytheon Engineers & Constructors, Inc. (215) 422-4144 | | Phila, PA, USA | | Any opinions I state are my own and not necessarily of my employer | |____________________________________________________________________|