PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

dateadd Function

 
 
ajmister
Guest
Posts: n/a
 
      23rd Aug 2004
Hi

I have a table

Create table tmp_name
( name char(15),
sales float,
yr char (4),
mth char (2)
)

and it has the following data

Joe Smith 15452.00 2001 03
Joe Smith 12157.00 2001 06
Joe Smith 14342.00 2001 09
Joe Smith 12429.00 2001 12
Joe Smith 13434.00 2002 03
Joe Smith 15529.00 2002 06
Joe Smith 15352.00 2002 09
Joe Smith 16436.00 2002 12

and I need to extract data for (max (yr) + max(mth)) and ((max(yr) +
max(mth)) - 12 mth) i.e.

name sales cur_yr cur_mth sales prv_yr
prv_mth
Joe Smith 16436.00 2002 12 12429.00 2001 12


Any suggestions
Ajay



 
Reply With Quote
 
 
 
 
Phil Robyn
Guest
Posts: n/a
 
      23rd Aug 2004
ajmister wrote:

> Hi
>
> I have a table
>
> Create table tmp_name
> ( name char(15),
> sales float,
> yr char (4),
> mth char (2)
> )
>
> and it has the following data
>
> Joe Smith 15452.00 2001 03
> Joe Smith 12157.00 2001 06
> Joe Smith 14342.00 2001 09
> Joe Smith 12429.00 2001 12
> Joe Smith 13434.00 2002 03
> Joe Smith 15529.00 2002 06
> Joe Smith 15352.00 2002 09
> Joe Smith 16436.00 2002 12
>
> and I need to extract data for (max (yr) + max(mth)) and ((max(yr) +
> max(mth)) - 12 mth) i.e.
>
> name sales cur_yr cur_mth sales prv_yr
> prv_mth
> Joe Smith 16436.00 2002 12 12429.00 2001 12
>
>
> Any suggestions
> Ajay
>
>
>

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>type c:\temp\mydata.dat
Joe Smith 15452.00 2001 03
Joe Smith 12157.00 2001 06
Joe Smith 14342.00 2001 09
Joe Smith 12429.00 2001 12
Joe Smith 13434.00 2002 03
Joe Smith 15529.00 2002 06
Joe Smith 15352.00 2002 09
Joe Smith 16436.00 2002 12

C:\cmd>demo\DoMyData
name sales cur_yr cur_mth sales prev_yr prev_mth
Joe Smith 16436.00 2002 12 12429.00 2001 12

C:\cmd>rlist demo\DoMyData.cmd
=====begin C:\cmd\demo\DoMyData.cmd ====================
01. @echo off
02. setlocal
03. for /f %%a in (
04. 'find /v /c "" ^< c:\temp\mydata.dat'
05. ) do set linecount=%%a
06. set /a start = linecount - 1
07. for /f "tokens=*" %%a in (
08. 'more /e +%start% ^< c:\temp\mydata.dat'
09. ) do set lastline=%%a
10. for /f "tokens=3-5" %%a in (
11. "%lastline%"
12. ) do set cur_sales=%%a&set cur_yr=%%b&set cur_month=%%c
13. set /a prev_yr = cur_yr - 1
14. for /f "tokens=*" %%a in (
15. 'findstr /c:"%prev_yr% %cur_month%" c:\temp\mydata.dat'
16. ) do set prev_results=%%a
17. echo name sales cur_yr cur_mth sales ^
18. prev_yr prev_mth
19. echo %prev_results:~0,9% %cur_sales% %cur_yr% %cur_month% ^
20. %prev_results:~11%
=====end C:\cmd\demo\DoMyData.cmd ====================
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DateAdd Function Mel Microsoft ASP .NET 1 7th Nov 2008 08:20 PM
Dateadd function =?Utf-8?B?RHIuIE1hdW51aw==?= Microsoft Excel Misc 2 28th Sep 2007 07:32 AM
DateAdd Function =?Utf-8?B?Q2hyaXN0NA==?= Microsoft Access Forms 3 10th Aug 2006 04:03 AM
Help with DateAdd Function rob Microsoft VB .NET 2 11th Feb 2006 08:17 PM
DateAdd Function =?Utf-8?B?UlRpbWJlcmxha2U=?= Microsoft Access Queries 4 25th Jan 2006 10:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:49 AM.