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 |
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-23 : 06:57:59
|
Hi... I am having these queriseinsert into password_management(User_id,current_password,old_pasword,pwd_change_date)values(_User_id,_current_password,_old_pasword,current_date());insert into password_management(security_q1,answer1)(select Security_Question_ID,Security_Answer from app_user where User_id=_User_id);While executing these queries 2 rows created ..like thisuser_id...current_password...Old_password...password_created_date...security_q1...answer11.......xxxxxxx.....yyyyyy....23/10/2010....null...nullnull....null....null.....null...2...fineMy need is these two rows must be combined into single one1.......xxxxxxx.....yyyyyy....23/10/2010....2...fine |
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-23 : 07:54:44
|
You can use a simple join to on user_id to get the matching rows.PBUH |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-23 : 08:00:46
|
Tnx for reply ..I need some more explanation can you ?? Please... |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-23 : 08:08:39
|
You wrote 2 different insert statements.So it is going to insert 2 rows.if both the rows you are inserting are related then you canjoin them to create a single select statement which you can insert.We need some more explaination from you.PBUH |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-23 : 08:19:20
|
Sure..I will give you...I have two tables user_table and password_tableAt the new registration of a user datas will be stored in user_table...If the user changes his password then the password will be updated and the old and new password are stored in password_table ...At this time of inserting the old and new password in password table security question from the user_table must be copied to password table.. |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-23 : 08:58:30
|
what if the password is changed multiple times?Should it insert a new record in the password table?PBUH |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-23 : 09:04:22
|
Yes..It is act as a log ..New record must inserted .. |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-23 : 11:12:42
|
You can write a insert trigger on the users table that will insert the data in the password table if any user password is updated in the users tablePBUH |
 |
|
|
|
|