Question: I am using DatePickerDialog library to get date picker while clicking on time textField. However, when I click on the Trainer-2 textField which is above the time textField then keyboard appears which is fine but when I click on time textField then the keyboard does not disappear and date picker appears behind it so the page gets stuck. 

Below is the code.

```
func textFieldDidBeginEditing(_ textField: UITextField) {

if textField == timeTextField {

self.view.endEditing(true)
self.getTime(textField: textField)

}

}

func getTime(textField: UITextField) {

DispatchQueue.main.async {

            DatePickerDialog().show(title: "DatePicker", doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: .time) {
                (time) -> Void in
                guard let date_time = time else { return }

}
}

```

Below are the images. 

1)When click on Trainer-1 textfield, keyboard appears which is fine.

[![when click on trainer-1 textfield ](https://i.stack.imgur.com/189yn.png)](https://i.stack.imgur.com/189yn.png)

2)when click on time textfield to get the datePicker

[![when click on time textField](https://i.stack.imgur.com/XrD6K.png)](https://i.stack.imgur.com/XrD6K.png)

I just want keyboard to disappear when click on time textField to gett he DatePicker.

Thanks.

Answer: 
Rather than doing both an UPDATE *and* an INSERT like your existing stored proc does (which will **guarantee** at least one extra row is added), you should try one of two options.

* Only run the INSERT if the UPDATE had no effect (by checking `@@ROWCOUNT = 0`)
* Use a [MERGE](https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql)
I solved my problem by modifiyng this procedure:

```
 --UPDATE EXISTING RECORDS      
                    UPDATE [ENVNDIVDB].[dbo].[TBL_PROC_PMS] SET _GOODS_CD=@_GOODS_CD,_GOODS_NAME=@_GOODS_NAME,  _UNIT = @_UNIT,_QTY=@_QTY,
                    [_UPDATE_DATE]=(select LEFT(CONVERT(VARCHAR, GETDATE(), 111), 10))                      
                     WHERE _PROCESS_INST_NO=@_PROCESS_INST_NO AND  _LINE_NO = @_LINE_NO 
        --INSERT NON-EXISTING RECORDS
         IF (@@ROWCOUNT = 0) 
            BEGIN
                 INSERT INTO [TBL_PROC_PMS]([INDEXNO],[_PROCESS_INST_NO],[_Order_No],[_LINE_NO],[_GOODS_CD],[_GOODS_NAME],[_UNIT],[_QTY],[_UPDATE_DATE])    
                 VALUES(@INDEXNO,@_PROCESS_INST_NO,@_Order_No,@_LINE_NO,@_GOODS_CD,@_GOODS_NAME,@_UNIT,@_QTY,(select LEFT(CONVERT(VARCHAR, GETDATE(), 111), 10)))

            END

```