<% Server.ScriptTimeOut = 60 * 5 Dim SQL,Rcset Dim COMMAND : COMMAND = Request("COMMAND") Dim CRUD : CRUD = Request("CRUD") Dim JSON Dim iCnt,cCnt Dim Field Dim PKEY : PKEY = Request("PKEY") Dim QID : QID = Request("QID") Dim QIDARR Dim QORDER,STYPE,OPTIONS,NAME Set Rcset = Server.CreateObject("ADODB.RecordSet") Call DBConnect2() SELECT CASE CRUD ' SELECT ' CASE "SELECT" SELECT CASE COMMAND CASE "SELECTLIST" '프로젝트 세부 정보' response.ContentType = "application/json" SQL = " select GKEY,JSON_QUERY(PROJECTJSON,'$.must') as JSON from PROJECT where PKEY = '"&PKEY&"' FOR JSON AUTO " Rcset.Open SQL,DBConn,3,1,1 while not Rcset.eof response.write Rcset(0) Rcset.movenext wend response.end CASE "QUESTIONLIST" '문항 리스트' response.ContentType = "application/json" SQL = " select QID,QORDER,JSON_VALUE(QUESTIONJSON,'$.variable') as variable,JSON_VALUE(QUESTIONJSON,'$.explain') as explain,JSON_VALUE(QUESTIONJSON,'$.qtype') as qtype ,JSON_VALUE(QUESTIONJSON,'$.qgroup') as [qgroup],JSON_VALUE(QUESTIONJSON,'$.rota') as rota from QUESTION where PKEY = '"&PKEY&"' order by QORDER FOR JSON AUTO " Rcset.Open SQL,DBConn,3,1,1 IF Rcset.eof or Rcset.bof THEN response.write "[]" ELSE while not Rcset.eof response.write Rcset(0) Rcset.movenext wend END IF Response.end CASE "GROUP" ' 그룹 정보 response.ContentType = "application/json" SQL = " select QID,JSON_QUERY(QUESTIONJSON) as qx, CASE WHEN LOGICJSON <> '' THEN JSON_QUERY(LOGICJSON) ELSE '' END as jx, Qorder from kon.dbo.QUESTION where PKEY = '"&PKEY&"' and JSON_VALUE(QUESTIONJSON,'$.qgroup') = '"&REQUEST("GROUP")&"' order by Qorder FOR JSON AUTO " Rcset.Open SQL,DBConn,3,1,1 IF Rcset.eof or Rcset.bof THEN response.write "[]" ELSE while not Rcset.eof response.write Rcset(0) Rcset.movenext wend END IF Response.end CASE "GROUPLIST" response.ContentType = "application/json" SQL = " select OPTIONJSON from QOPTION where PKEY = '"&PKEY&"' and OTYPE = 'qgroup' " Rcset.Open SQL,DBConn,3,1,1 IF Rcset.eof or Rcset.bof THEN Response.Write "{}" ELSE Response.Write Rcset("OPTIONJSON") END IF Response.end CASE "QUESTION" '문항 정보' response.ContentType = "application/json" SQL = " select JSON_QUERY(QUESTIONJSON,'$') as JSON from QUESTION where PKEY = '"&PKEY&"' and QID = '"&QID&"' " Rcset.Open SQL,DBConn,3,1,1 response.write Rcset("JSON") response.end CASE "STRUCTURE" '데이터 구조' response.ContentType = "application/json" SQL = " select JSON_QUERY(QINFO,'$') as JSON from STRUCTURE where PKEY = '"&PKEY&"' " Rcset.Open SQL,DBConn,3,1,1 response.write Rcset("JSON") response.end CASE "LOGIC" ' 로직 정보 ' SQL = " select CASE WHEN LOGICJSON = '' THEN '' ELSE JSON_QUERY( LOGICJSON,'$') END as JSON from QUESTION where QID = '"&QID&"' and PKEY = '"&PKEY&"' " Rcset.Open SQL,DBConn,3,1,1 IF Rcset("JSON") <> "" THEN response.ContentType = "application/json" response.write Rcset("JSON") ELSE response.ContentType = "text/plain" response.write "" END IF response.end CASE "TOTALDATA" ' 총 부수 SQL = " SELECT COUNT(*) as cnt FROM DATA where Status='10' and SURVEY_TYPE <> 'TEST' and PKEY = '"& PKEY &"' group by Status " Rcset.Open SQL,DBConn,3,1,1 IF Rcset.eof or Rcset.bof THEN response.write "0" ELSE response.write Rcset("cnt") END IF response.end CASE "DATA" SQL = " select * from ( " IF request("TYPE") = "TEST" THEN SQL = SQL & " select IDKEY from DATA where PKEY = '" &PKEY& "' and Status='10' and SURVEY_TYPE = 'TEST' " ELSE SQL = SQL & " select IDKEY from DATA where PKEY = '" &PKEY& "' and Status='10' and SURVEY_TYPE <> 'TEST' " END IF SQL = SQL & " ) IA CROSS APPLY( " SQL = SQL & " select DISTINCT '{' + STUFF(( " SQL = SQL & " SELECT ',' + SUBSTRING(value,2, LEN(value)-2) " SQL = SQL & " FROM OPENJSON((SELECT JSON_QUERY(DATJSON,'$') from DATA where PKEY = '"& PKEY &"' and IDKEY = IA.IDKEY )) " SQL = SQL & " FOR XML PATH('') " SQL = SQL & " ),1,1,' ') + '}' AS DAT " SQL = SQL & " ) DAT FOR JSON AUTO " Rcset.Open SQL,DBConn,3,1,1 IF Rcset.eof or Rcset.bof THEN response.write "[]" ELSE While not Rcset.eof response.write Rcset(0) Rcset.movenext : wend END IF response.end CASE "DATA_BASE" SQL = SQL & " select [key] as qid ,variable,REPLACE(SUBSTRING([value],2,LEN([value])-2),'""','') as [value] from OPENJSON((SELECT QINFO fROM [STRUCTURE] where PKEY = '" & PKEY & "')) A CROSS APPLY( " SQL = SQL & " SELECT QORDER,JSON_VALUE(QUESTIONJSON,'$.variable') as variable FROM QUESTION B WHERE PKEY = '"& PKEY &"' and A.[key] collate Korean_Wansung_CI_AS = B.QID " SQL = SQL & " ) C where [value] <> '[]' ORDER BY QORDER FOR JSON AUTO" Rcset.Open SQL,DBConn,3,1,1 IF Rcset.eof or Rcset.bof THEN response.write "[]" ELSE While not Rcset.eof response.write Rcset(0) Rcset.movenext : wend END IF response.end END SELECT END SELECT call DBClose() %>