You are going to run into issues once your json payload is longer than nvarchar(max)
You need to talk to your "data architects" to rethink this approach as discussed in this thread
and if you insist on json approach trim down the json to
"q":[
{
"qn": 2,
"qd": "Are you attendig the event ?",
"mndtrQstnrInd": true,
"actvQstnrInd": true,
"answers": [
{
"an": 1,
"ad": "Yes",
"ai": true
},
etc
Also would not recommend using a CURSOR, use one pass batch approach like following
;with src
as
(
SELECT q.QSTN_NBR,
q.QSTN_DESC,
q.ACTV_QSTN_IND,
q.MNDTR_QSTN_IND,
a.ansNbr,
a.ansDesc,
a.actvAnsInd
FROM OpenJson(@QUES_ANS_DTL,'$.questions')
WITH (
QSTN_NBR int '$.qstrnNbr',
QSTN_DESC varchar(200) '$.qstrDesc',
ACTV_QSTN_IND bit '$.actvQstnrInd',
MNDTR_QSTN_IND bit '$.mndtrQstnrInd',
answers nvarchar(max) '$.answers' AS JSON
) as q
cross apply openjson (answers)
with
(
ansNbr int,
ansDesc nvarchar(100),
actvAnsInd bit
) as a
)
INSERT INTO dbo.QSTN(QSTN_NBR,
QSTN_DESC,
ACTV_QSTN_IND,
MNDTR_QSTN_IND,
CRTE_TSTP,
CRTE_USR_ID)
select QSTN_NBR,QSTN_DESC,ACTV_QSTN_IND,
MNDTR_QSTN_IND, getdate(), 'BUBBA'
from src
where not exists(select 1
from QSTN tgt
where tgt.QSTN_NBR = src.QSTN_NBR)