Subject | Re: Merging VARCHAR fields |
---|---|
Author | csswa |
Post date | 2002-06-02T08:06:06Z |
Or use the udf function SNVL from the latest FBUDF.DLL -- thanks to
Claudio (BTW, where is Claudio these days?). It works great. Here
are the changes you need:
DECLARE EXTERNAL FUNCTION UDF_SNVL
VARCHAR(300),
VARCHAR(300),
VARCHAR(300)
RETURNS PARAMETER 3
ENTRY_POINT 'sNvl' MODULE_NAME 'FBUDF';
-- note: set VARCHAR above to max length of string passed/returned.
SET TERM !! ;
create procedure move_dlvry_chg_to_notes
as
DECLARE VARIABLE SuplrNo integer;
declare variable ss varchar(300);
begin
for select SUPLRNO, ((udf_snvl(delivery_charge, '')) || ' ' ||
(udf_snvl(notes, ''))) from suppliers into :SuplrNo, :ss do
update suppliers set notes = :ss where SUPLRNO = :SuplrNo;
exit;
end !!
SET TERM ; !!
Regards,
Andrew Ferguson
-- Like a runt badger that nobody wants.
Claudio (BTW, where is Claudio these days?). It works great. Here
are the changes you need:
DECLARE EXTERNAL FUNCTION UDF_SNVL
VARCHAR(300),
VARCHAR(300),
VARCHAR(300)
RETURNS PARAMETER 3
ENTRY_POINT 'sNvl' MODULE_NAME 'FBUDF';
-- note: set VARCHAR above to max length of string passed/returned.
SET TERM !! ;
create procedure move_dlvry_chg_to_notes
as
DECLARE VARIABLE SuplrNo integer;
declare variable ss varchar(300);
begin
for select SUPLRNO, ((udf_snvl(delivery_charge, '')) || ' ' ||
(udf_snvl(notes, ''))) from suppliers into :SuplrNo, :ss do
update suppliers set notes = :ss where SUPLRNO = :SuplrNo;
exit;
end !!
SET TERM ; !!
Regards,
Andrew Ferguson
-- Like a runt badger that nobody wants.
--- In ib-support@y..., Helen Borrie <helebor@t...> wrote:
> At 05:39 AM 01-06-02 +0000, you wrote:
> >Is there anything wrong with the following? It executes without
> >error, but the NOTES field is unchanged afterwards.
> >NOTES & DELIVERY_CHARGE are VARCHAR(256) & VARCHAR(40 respectively.
> >
> >SET TERM !! ;
> >create procedure move_dlvry_chg_to_notes
> >as
> > DECLARE VARIABLE SuplrNo integer;
> > declare variable ss varchar(300);
> >begin
> > for select SUPLRNO, (delivery_charge || ' ' || notes) from
> >suppliers into :SuplrNo, :ss
> > do
> > begin
> > update suppliers set notes = :ss where SUPLRNO
= :SuplrNo;
> > end
> >end !!
> >SET TERM ; !!
>
> The problem with concatenating two columns is that, if one is null,
the
> whole result will be null. The usual ways to deal with such a
problem are
> to either enforce a default empty string on the column at create
and update
> time (by a trigger); or to perform concatenations via stored
procedure
> where you can test for null and handle it appropriately.
>
> heLen
>
>
> All for Open and Open for All
> Firebird Open SQL Database · http://firebirdsql.org ·
> http://users.tpg.com.au/helebor/
> _______________________________________________________