Wrox Programmer Forums
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2005, 10:36 AM
Authorized User
 
Join Date: Sep 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trigger

I need to create an insert trigger. My situation is this:
Field A is populated with value '123456' at this point the trigger responds to this insert by executing an algorithm that converts '123456' to 'ABCDEF' where the alpha letter coresponds to the numeric order. I then need this trigger to populate Field B with 'ABCDEF'.

Any help would be appreciated.



 
Old January 27th, 2005, 11:01 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Do you already have the algorithm to change the column from '123456' to a string
Look at this example:
Code:
create trigger as update_insert_b
on <your table>
for insert
as
if update(col_A)
begin
update <your table>
set col_B=col_A
from <your Table> A
join inserted i
on A.id=i.id
where A.col_A='Your Value'-- our what ever you decide
end
Jaime E. Maccou
 
Old January 27th, 2005, 11:10 AM
Authorized User
 
Join Date: Sep 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jaime,
The algorithm is what I need help with.
I suspect that I would need to use CASE in this situation?

Select Col_A,
Case Col_A
When '123456' then 'ABCDEF'
End as Col_B

Something along these lines but I am having trouble conceptualizing.

 
Old January 27th, 2005, 11:33 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

I have never used it before but books online has an example that may be helpful.

Examples
A. Use ASCII and CHAR to print ASCII values from a string
This example prints the ASCII value and character for each character in the string New Moon.

SET TEXTSIZE 0
-- Create variables for the character string and for the current
-- position in the string.
DECLARE @position int, @string char(8)
-- Initialize the current position and the string variables.
SET @position = 1
SET @string = 'New Moon'
WHILE @position <= DATALENGTH(@string)
   BEGIN
   SELECT ASCII(SUBSTRING(@string, @position, 1)),
      CHAR(ASCII(SUBSTRING(@string, @position, 1)))
   SET @position = @position + 1
   END
GO



Jaime E. Maccou
 
Old January 27th, 2005, 11:49 AM
Authorized User
 
Join Date: Sep 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks let me study this.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Trigger Help monika.vasvani SQL Language 2 March 1st, 2007 06:59 AM
Trigger arshad mahmood C++ Programming 4 June 24th, 2004 07:10 AM
Trigger ! minhtri Pro VB Databases 2 June 23rd, 2004 02:27 AM
Trigger arshad mahmood SQL Language 2 May 12th, 2004 05:16 AM
Using instead of trigger dmr999 SQL Server 2000 1 November 29th, 2003 02:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.