1

There is a table with existing records with different entity ids, now need to insert records in the Table using Cursor and without hard coding the records.

Please find my script below.

DECLARE @txId varchar(50) Declare @UserRole_id int @txId = NEWID()

    set @UserRole_id = (SELECT @UserRole_id = MAX(User_Role_Id) + 1 FROM USER_TB

INSERT INTO USER_ROLE_TB (User_Role_id, entity_Id, User_role_code, User_Role_description, Print_Sequence, Update_date, Tx_id, Add_date, Add_Username, Update_Username, Active_Flag)

     Values...

(@UserRole_id,entity_Id,'ACH ','AC-HEATING',7,GETUTCDATE(),@txID,GETDATE(),'30383212','30383212',1) (@UserRole_id,entity_Id,'BRAKE TECH','BRAKE',8,GETUTCDATE(),@txID,GETDATE(),'30383212','30383212',1) (@UserRole_id,Pos_entity_Id,'CASH OUT','CASH OUT TECHNICIAN',4,GETDATE(),@txID,GETDATE(),'30383212','30383212',1)

Here i have hardcoded the records what if i have to insert new records. Im not sure how do i do it.

i got to insert in these column without harding coding them and using cursor.

Not so familiar with Cursor. Please help.

Sandy777
  • 41
  • 2
  • 8
  • I am not clear what you are asking. Are you attempting to update user_role_tb columns user_role_id and tx_id - which currently have null values and all the other columns are filled? – P.Salmon Mar 28 '17 at 11:43
  • The User_role_id and tx_id are genrated automatically, I just want to know how do i insert the Data in User_role_tb without hard coding the records like i have done in the above. – Sandy777 Mar 28 '17 at 12:25
  • Data has to come from somewhere if you don't want to hardcode it - so where does it come from in your case? – P.Salmon Mar 29 '17 at 08:29

0 Answers0