Subject | Re: [ib-support] Re: Duplication records |
---|---|
Author | Helen Borrie |
Post date | 2001-07-08T08:08:08Z |
Lee,
A few things here...
QTIB_Pim.SQL.Clear;
The input columns list has to be enclosed in brackets, as shown in Svein's example:
QTIB_Pim.SQL.Add('insert into PIM (EMP,DATE_START,DATE_END,PIMAGE)');
QTIB_Pim.SQL.Add('select EMP,DATE_START + :DaysToMove,DATE_END
+ :DaysToMove,PIMAGE from PIM');
Don't attempt to construct SQL using concocted date literals - they almost invariably fail. Get your Start and End dates as TDateTimes and use parameters:
QTIB_Pim.SQL.Add('where DATE_START >= :StartDate and
DATE_START < :EndDate' + 1');
Here is where the call to Prepare goes, if needed (but it's not needed for IBO):
QTIB_Pim.Prepare;
Now this line:
// !!! QTIB_Pim.SQL.Add('parambyname(:daystomove).AsInteger := 2;'); !!!
This isn't how it's done! ParamByName is a method of the Columns object (in IBO) or the Fields object (in IBX and the BDE) - it doesn't go into the SQL. Take another look at Svein's example...
QTIB_Pim.ParamByName(:daystomove).AsInteger := 2;
QTIB_Pim.ParamByName(:StartDate).AsDateTime := StartDate; // a TDateTime variable
QTIB_Pim.ParamByName(:EndDate).AsDateTime := EndDate; // another TDateTime variable
// QTIB_Pim.Prepare; Not needed in IBO; in the wrong place in any case
QTIB_Pim.Execute;
You'll get there eventually. :-))
Cheers.
Helen
At 07:45 AM 08-07-01 +0000, you wrote:
InterBase Developer Initiative · http://www.interbase2000.org
_______________________________________________________
A few things here...
QTIB_Pim.SQL.Clear;
The input columns list has to be enclosed in brackets, as shown in Svein's example:
QTIB_Pim.SQL.Add('insert into PIM (EMP,DATE_START,DATE_END,PIMAGE)');
QTIB_Pim.SQL.Add('select EMP,DATE_START + :DaysToMove,DATE_END
+ :DaysToMove,PIMAGE from PIM');
Don't attempt to construct SQL using concocted date literals - they almost invariably fail. Get your Start and End dates as TDateTimes and use parameters:
QTIB_Pim.SQL.Add('where DATE_START >= :StartDate and
DATE_START < :EndDate' + 1');
Here is where the call to Prepare goes, if needed (but it's not needed for IBO):
QTIB_Pim.Prepare;
Now this line:
// !!! QTIB_Pim.SQL.Add('parambyname(:daystomove).AsInteger := 2;'); !!!
This isn't how it's done! ParamByName is a method of the Columns object (in IBO) or the Fields object (in IBX and the BDE) - it doesn't go into the SQL. Take another look at Svein's example...
QTIB_Pim.ParamByName(:daystomove).AsInteger := 2;
QTIB_Pim.ParamByName(:StartDate).AsDateTime := StartDate; // a TDateTime variable
QTIB_Pim.ParamByName(:EndDate).AsDateTime := EndDate; // another TDateTime variable
// QTIB_Pim.Prepare; Not needed in IBO; in the wrong place in any case
QTIB_Pim.Execute;
You'll get there eventually. :-))
Cheers.
Helen
At 07:45 AM 08-07-01 +0000, you wrote:
>svein,All for Open and Open for All
>I tried this but got errors in the prepare.
> 'Token unknown EMP'
>What is wrong with this statement ?
>The where statement on its own works.
>
>QTIB_Pim.SQL.Clear;
>QTIB_Pim.SQL.Add('insert into PIM EMP,DATE_START,DATE_END,PIMAGE');
>QTIB_Pim.SQL.Add('select EMP,DATE_START + :DaysToMove,DATE_END
>+ :DaysToMove,PIMAGE from PIM');
>QTIB_Pim.SQL.Add('where DATE_START >= ' + Date_Start_String + ' and
>DATE_START <= ' + Date_End_String);
>QTIB_Pim.SQL.Add('parambyname(:daystomove).AsInteger := 2;');
>QTIB_Pim.Prepare;
>QTIB_Pim.Execute;
>
>Thanks aforehand
>Lee
>
>--- In ib-support@y..., Svein Erling Tysvær
><svein.erling.tysvaer@k...> wrote:
> > Hi Lee,
> >
> > INSERT INTO PIM (listoffieldstoinsert)
> > SELECT somefields, DATE_START + :DaysToMove, morefields
> > FROM PIM
> > WHERE keyfield = :SomeValue
> > Prepare the statement, set the parameters
> > (ParamByName(:DaysToMove).AsInteger:=something;) and execute the
>statement.
> >
> > Simple and easy,
> > Set
> >
> > >In a database I got appointments with a timestamp field.
> > >How can I duplicate a specific appointment to another date ?
> > >So suppose I got a appointment on 2001/01/01 and I want to
>duplicate
> > >this appointment to 2001/02/01 how do I write a sql command for
>this ?
> > >The appointment fields are the same, only the timestamp field is
> > >different.
> > >I know how to move :
> > >('update PIM set DATE_START = DATE_START + ' + IntTostr
>(Days_To_Move)
> > >+ ' where DATE_START = ' + Date_Start_String);
> > >But what is the syntax for duplicating a record?
>
>
>To unsubscribe from this group, send an email to:
>ib-support-unsubscribe@egroups.com
>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
InterBase Developer Initiative · http://www.interbase2000.org
_______________________________________________________