Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
temuri
Starting Member
8 Posts |
Posted - 2011-03-30 : 17:42:45
|
| HI! I need some help with query.I have two tables;Tab1;(userid,orgname,date)Tab2;(userid,orgname,date)Tab3;(userid,orgname,date)I need to add user from Table1 to table2 and table3 if not exist by month.system check if new user added to Table1; and automatically add different to Table2 and Table3 but in same date(year,month)Is it possible to make ik by sql server, with scheduler or somethingcan someone help me ? |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2011-03-30 : 18:08:29
|
| Can you provide us with sample data of what you'd like to accomplish?Sounds like you'll need to create a trigger that adds users to Table2 and Table3 whenever a new user is inserted into Table1.Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
temuri
Starting Member
8 Posts |
Posted - 2011-03-30 : 18:17:20
|
| yap I think that I need make triger in sql server but i didn't know where to do this and also need help with QueryI need just add userid,orgname and date from table 1 |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2011-03-30 : 18:30:02
|
This should give you an idea on what you'd have to do:USE YourDatabaseNameIF EXISTS (SELECT name FROM sysobjects WHERE name = 'YourTriggerName' AND type = 'TR') DROP TRIGGER YourTriggerNameGOCREATE TRIGGER YourTriggerNameON Table1AFTER INSERTASBEGINSET NOCOUNT ON;INSERT Table2SELECT * FROM insertedINSERT Table3SELECT * FROM insertedENDGO Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
temuri
Starting Member
8 Posts |
Posted - 2011-03-30 : 18:38:34
|
| I will try thank you; |
 |
|
|
temuri
Starting Member
8 Posts |
Posted - 2011-03-31 : 19:39:00
|
| It's works perfect!!with INSERTED its mean table name or inserted data only ???? |
 |
|
|
|
|
|