If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Changing values in inserting record via triggers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-22-02, 08:45
niras niras is offline
Registered User
 
Join Date: Jan 2002
Posts: 4
Changing values in inserting record via triggers

Hi

Does anyone of you know how I ca create a trigger to do the following

Table tbs contain 3 columns : total, num_col and alpha_col

I'm doing an insert in table tbs:
insert into tbs (total) values ('111aaa')

Now I want the trigger to split '111aaa' in to parts: An numeric and a characterpart. The trigger should store the numeric part (111) in column num_col. And the characterpart should be stored in alpha_col.

Can anyone help ?!?!?


Torsten
Reply With Quote
  #2 (permalink)  
Old 01-22-02, 15:35
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Hi Torsten,

this is a soultion for Oracle:

BEGIN
select trim(translate(:new.field1, '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM NOPQRSTUVWXYZ',
' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX YZ')) into FieldNum from dual;

select trim(translate(:new.field1, '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM NOPQRSTUVWXYZ',
'1234567890 ')) into fieldChar from dual;

UPDATE table set fieldnumeric = TO_NUMBER(FieldNum),
fieldvarchar = fieldChar;
END;

Hope this helps ?

Manfred Peter
(Alligator Company)
http://www.alligatorsql.com
Reply With Quote
  #3 (permalink)  
Old 01-24-02, 07:12
niras niras is offline
Registered User
 
Join Date: Jan 2002
Posts: 4
Quote:
Originally posted by alligatorsql.com
Hi Torsten,

this is a soultion for Oracle:

BEGIN
select trim(translate(:new.field1, '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM NOPQRSTUVWXYZ',
' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX YZ')) into FieldNum from dual;

select trim(translate(:new.field1, '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM NOPQRSTUVWXYZ',
'1234567890 ')) into fieldChar from dual;

UPDATE table set fieldnumeric = TO_NUMBER(FieldNum),
fieldvarchar = fieldChar;
END;

Hope this helps ?

Manfred Peter
(Alligator Company)
http://www.alligatorsql.com
Hi Manfred
Thanks for your answer.
What I need to do is on a SQL Server.
I'll try and see, if I can modify your suggestion, so it fits into a SQLServer environment. But I can't find a SQLServer thing like Oracles :new.field1. Do you know if theres a way to reference columns in the current record in a SQLServer trigger ?

Torsten
Reply With Quote
  #4 (permalink)  
Old 01-24-02, 12:13
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Hello Torsten,

there must be a way to manipulate the current triggerfields; otherwise its would make less sence to program a trigger.
Perhaps you try it in the MS Server forum. I havenīt got a documentation af that database, but it canīt be to difficult to figure this out ...

Greetings
Manfred Peter
(Alligator Company)
http://www.alligatorsql.com
Reply With Quote
  #5 (permalink)  
Old 07-24-02, 01:42
cslaughter cslaughter is offline
Registered User
 
Join Date: Jul 2002
Posts: 1
You're going to need to reference the inserted object in SQLServer. Like :new.field in Oracle, you can reference inserted.field by using a join between your base table (table1) and inserted.

Select table1.field from inserted.fieldkey where table1.fieldkey=insert.fieldkey.

Hope this helps.

Chris
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On