Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Insert Statement based on group totals
Wed, Mar 27 2013 7:13 AMPermanent Link

Alex Vastich

Hi,

Not sure what I am doing wrong here but here are my statements:

select 2005 as yr, count(hiredate) as headcnt into memory memCalc from memory memStaff where ( ( terminatedate = null ) or ( terminatedate >= '2005-01-01' ) ) and ( hiredate <= '2005-12-31' );

insert into memory memCalc (yr, headcnt)
select 2006, count(hiredate) from memory memStaff where ( ( terminatedate = null ) or ( terminatedate >= '2006-01-01' ) ) and ( hiredate <= '2006-12-31' );;

The first statement creates the memory table fine with a single record.  the second I am trying to insert a record but the error I am receiving is:

Type mismatch between column headcnt and constant value in Insert statement.  

I am using DBISAM V3.3. Seemsstraight forward.  Am i missing something.  help appreciated.
Wed, Mar 27 2013 8:36 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Alex


What does memCalc do?

I assume the missing ; after insert into memory memCalc (yr, headcnt) is just a typo for the post

yr in statement 1 is an integer what does memCalc return it as?

V3 is a long time ago, I wasn't using SQL much back then and I'm not even sure the syntax is allowable.


Roy Lambert [Team Elevate]
Wed, Mar 27 2013 4:20 PMPermanent Link

Jeff Cook

Aspect Systems Ltd

Avatar

Hi Alex

I changed your SQL to use one of my own DBISAM v3 tables that had two dates
and it executed OK:-
=============================================================
SELECT TransDate AS hiredate,
              DueDate AS terminatedate
INTO MEMORY memStaff
FROM SupplierTrans
;
select 2005 as yr, count(hiredate) as headcnt
into memory memCalc
from memory memStaff
where ( ( terminatedate = null ) or ( terminatedate >= '2005-01-01' ) )
  and ( hiredate <= '2005-12-31' )
;
insert into memory memCalc (yr, headcnt)
select 2006, count(hiredate)
from memory memStaff
where ( ( terminatedate = null ) or ( terminatedate >= '2006-01-01' ) )
  and ( hiredate <= '2006-12-31' )
;
SELECT * FROM MEMORY memCalc
=============================================================
.... BUT the two records created had null in the "yr" column, which I can't
account for.

Good Luck!

Cheers

Jeff



--
Jeff Cook
Aspect Systems Ltd
www.aspect.co.nz

<Alex Vastich> wrote in message
news:2B9186E0-9723-4EAE-8622-545CE543752E@news.elevatesoft.com...
> Hi,
>
> Not sure what I am doing wrong here but here are my statements:
>
> select 2005 as yr, count(hiredate) as headcnt into memory memCalc from
> memory memStaff where ( ( terminatedate = null ) or ( terminatedate >=
> '2005-01-01' ) ) and ( hiredate <= '2005-12-31' );
>
> insert into memory memCalc (yr, headcnt)
> select 2006, count(hiredate) from memory memStaff where ( ( terminatedate
> = null ) or ( terminatedate >= '2006-01-01' ) ) and ( hiredate <=
> '2006-12-31' );;
>
> The first statement creates the memory table fine with a single record.
> the second I am trying to insert a record but the error I am receiving is:
>
> Type mismatch between column headcnt and constant value in Insert
> statement.
>
> I am using DBISAM V3.3. Seemsstraight forward.  Am i missing something.
> help appreciated.
>

Wed, Mar 27 2013 10:53 PMPermanent Link

Alex Vastich

Wow thanks Jeff. Very weird then as I still get the error but can't see any genuine difference between your statement and mine.  This one really has me stumped.
Image