Narasiman nar

Narasiman nar

  • NA
  • 64
  • 20.1k

When update duplicate rows inserted

Jun 5 2018 8:29 AM
  1. ALTER PROCEDURE [dbo].[sp_update_farmer_registration_web]   
  2. @originname varchar(100),   
  3. @farmerctscode varchar(100),   
  4. @farmerseason varchar(100),   
  5. @dateofjoinseco varchar(100),   
  6. @governmentcode varchar(100),   
  7. @firstname varchar(100),   
  8. @lastname varchar(100),   
  9. @surname varchar(100),   
  10. @gender varchar(100),   
  11. @dateofbirth varchar(100),   
  12. @birthlocation varchar(100),   
  13. @fathername varchar(100),   
  14. @mothername varchar(100),   
  15. @village varchar(100),   
  16. @currentyearcooperative varchar(100),   
  17. @phonenumber varchar(100),   
  18. @observation varchar(100),   
  19. @nooffarms varchar(100),   
  20. @productionestimation varchar(100),   
  21. @otherdetails varchar(max),   
  22. @previouscropsdetails varchar(max),  
  23. @firstlevelapprovalstatus varchar(100),   
  24. @firstlevelapprovedby varchar(100),   
  25. @secondlevelapprovalstatus varchar(100),   
  26. @secondlevelapprovedby varchar(100),   
  27. @firstlevelcomments varchar(max),   
  28. @secondlevelcomments varchar(max),   
  29. @updatedby varchar(100),   
  30. @mastertype varchar(100)   
  31. AS   
  32. BEGIN   
  33. SET NOCOUNT ON;   
  34. DECLARE @sqlQuery VARCHAR(MAX)   
  35. IF @mastertype = ''   
  36. BEGIN   
  37. SET @sqlQuery = 'UPDATE dbo.tbl_farmerregistration_' + @originname + ' SET farmerseason = ''' + @farmerseason + ''',   
  38. dateofjoinseco = ''' + @dateofjoinseco + ''', governmentcode =''' + @governmentcode + ''', firstname = ''' + @firstname + ''',   
  39. lastname = ''' + @lastname + ''', surname = ''' + @surname + ''', gender = ''' + @gender + ''', dateofbirth = ''' + @dateofbirth + ''',   
  40. birthlocation = ''' + @birthlocation + ''', fathername = ''' + @fathername + ''', mothername = ''' + @mothername + ''',   
  41. village = ''' + @village + ''', currentyearcooperative = ''' + @currentyearcooperative + ''',   
  42. phonenumber = ''' + @phonenumber + ''', observation = ''' + @observation +''', nooffarms = ''' + @nooffarms + ''', produtionestimation = ''' + @productionestimation + ''',   
  43. otherdetails = ''' + @otherdetails + ''',previouscropsdetails = ''' + @previouscropsdetails + ''',   
  44. updatedby = ''' + @updatedby + ''', updateddate = GETDATE()   
  45. WHERE farmerctscode = ''' + @farmerctscode + ''''   
  46. END  
This is the above SP
 
When i execute the below query as follows
  1. UPDATE dbo.tbl_farmerregistration_ivorycoast SET farmerseason = '2019',  
  2. dateofjoinseco = '2012', governmentcode ='402787J', firstname = 'KITCHINDJOUHOU',lastname = 'OUATTARA', surname = 'A', gender = 'MALE', dateofbirth = '17/5/1981',birthlocation = 'FERKESSEDOUGOU', fathername = 'OUATTARA MEYERIGUE', mothername = 'OSSIELETIAN OUATTARA',  
  3. WHERE farmerctscode = '1050669'  
i get output in sql 2 rows affected in a table tbl_farmerregistration_ivorycoast two rows inserted for that farmerctscode = '1050669'
 
farmerseason dateofjoinseco governmentcode firstname lastname surname gender dateofbirth birthlocation fathername mothername
2019 2012 402787J KITCHINDJOUHOU OUATTARA A MALE 17/5/1981 Ferek Ras Osel
2019 2012 402787J KITCHINDJOUHOU OUATTARA A MALE 17/5/1981 Ferek Ras Osel
 
how to fix this issue.
 
please let me know.

Answers (3)