Monday, January 21, 2013 3:48 PM
I think this is fairly easy for a person who knows SQL , I am not a programming guy so no idea how to deal this . Please see below and help me suggesting how to achieve the result .
I am having a table called cdrlocaluk which has 6 column ( srno (PK) /date / time / sec / cnum / dnum ) , now I want to add another column (switchname) and update that column with every insert operation with a value of 'UK-Switch'. Post this I want to copy this updated record including the new column ( srno (PK) /date / time / sec / cnum / dnum / switchname ) to a new table called globalcdr .
I am not sure how to write this process in a trigger format , I tried what all I can gather from google and msdn however without any luck .
Monday, January 21, 2013 3:57 PM
Bellow you can find the code:
ALTER TABLE cdrlocaluk ALTER COLUMN switchname NVARCHAR(20) NOT NULL;
UPDATE cdrlocaluk SET switchname = N'UK-Switch' WHERE switchname IS NULL;
INSERT INTO globalcdr
SELECT * FROM cdrlocaluk
You have to pay attention that before you run this query you should already have created a table called globalcdr which has the same structure with cdrlocaluk
Thanks in advance, Ciprian LUPU
Monday, January 21, 2013 4:01 PMModerator
I am guessing:
1. Add a new column to the cdrlocaluk table with default value of 'UK-Switch' .
2. Use the OUTPUT clause in the cdrlocaluk INSERT statement to INSERT into globalcdr table (DOUBLE INSERT).
No trigger necessary for the above.
OUTPUT clause example:
Kalman Toth SQL 2008 GRAND SLAM
Paperback: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012
- Edited by Kalman TothMicrosoft Community Contributor, Moderator Monday, January 21, 2013 4:02 PM
- Proposed As Answer by dgjohnson Monday, January 21, 2013 4:05 PM
- Marked As Answer by Allen Li - MSFTModerator Wednesday, January 30, 2013 2:22 AM