<% Set dbCon = Server.CreateObject("ADODB.Connection") dbCon.open ("DSN=UID=PWD=") Set rsTmp = Server.CreateObject("ADODB.Recordset") ' 테이블명 insTb = "test" ' 사용필드 insFd = Array(ex_no, ex_writer, ex_content, ex_wdate) ' 실입력값 insVal = Array(0, "'운영자'", "'SQL 구문 모듈화 연습'", "'2002-12-17'") ' 변환하다 보니 함수를 호출할 때 문자(열)형의 인수에는 반드시 작은따옴표로 ' 묶어서 넘겨줘야 SQL구문에서 문자열 인식을 할 수 있을 것 같다는 생각이... if insSql(insTb, insFd, insVal) then response.write ("정상적으로 입력 되었습니다.") else response.write ("정상적으로 입력하지 못하였습니다.") end if ' 테이블명 delTb = "test" ' 삭제 검색 필드 delFd = Array(ex_no, ex_writer) ' 삭제 검색 값 delVal = Array(0, "'운영자'") ' 삭제 검색 조건 delCon = "AND" ' Delete나 Update에서의 처리 조건을 설정 할 필요가 있을 경우에 있어서 ' va AND vb AND vc 혹은 va OR vb OR vb와 같은 단일조건만을 적용한 ' 검색만 가능하다고 보임... ' ((va AND vb) OR vc)는 어떻게 처리하지??? ' 우선순위 등의 설정에 대해서 좀 더 고려를 해봐야 할 듯... if delSql(delTb, delFd, delVal, delCon) then response.write ("정상적으로 삭제 되었습니다.") else response.write ("정상적으로 삭제하지 못하였습니다.") end if ' 테이블명 updTb = "test" ' 업데이트 필드 updSFd = Array(ex_writer) ' 업데이트 값 updSVal = Array("'항아'") ' 업데이트 조건 필드 updDFd = Array(ex_writer) ' 업데이트 조건 값 updDVal = Array("'운영자'") ' 업뎃 검색 조건 updCon = "" if updSql(updTb, updSFd, updSVal, updDFd, updDVal, updCon) then response.write ("정상적으로 업데이트 되었습니다.") else response.write ("정상적으로 업데이트되지 못하였습니다.") end if ' ------------------------------------------------------------ ' Insert Statement ' ------------------------------------------------------------ function insSql(tbName, insFd(), insDat()) insSql = false ' INSERT구문의 정상적인 처리를 Check하기 위해서... ' insFd 와 insDat의 배열 원소 갯수 체크. if UBound(insFd) <> UBound(insDat) then response.write ("주어진 필드의 수와 입력 데이터의 수가 일치하지 않습니다.") exit function end if ' insFd 구문 작성 insStr = "" for i = LBound(insFd) to UBound(insFd) insStr = insStr & insFd(i) insStr = insStr & "," next i ' insStr SQL 구문에서 마지막 Comma(,)를 삭제. insStr = RTrim(insStr) if Right(insStr, 1) = "," then insStr = Left(insStr, Len(insStr) - 1) end if insStr = "INSERT INTO " & tbName & " (" & insStr & ")" ' insDat 구문 작성 valStr = "" for i = LBound(insDat) to UBound(insDat) valStr = valStr & insDat(i) valStr = valStr & "," next i ' valStr SQL 구문에서 마지막 Comma(,)를 삭제. valStr = RTrim(valStr) if Right(valStr, 1) = "," then valStr = Left(valStr, Len(valStr) - 1) end if valStr = " VALUES(" & valStr & ")" dbCon.execute (insStr & valStr) insSql = ture ' INSERT구문이 정상적으로 처리가 완료되면... ture! end function ' ------------------------------------------------------------ ' Delete Statement ' ------------------------------------------------------------ function delSql(tbName, delFd(), delVal(), delCon) delSql = false if UBound(delFd) <> UBound(delVal) then begin response.write ("주어진 필드의 수와 입력 데이터의 수가 일치하지 않습니다.") exit function end if delStr = "DELETE FROM " & tbName posStr = "" for i = LBound(delFd) to UBound(delFd) posStr = posStr & delFd(i) & "=" & delVal(i) posStr = posStr & " " & delCon & " " next i posStr = RTrim(posStr) chkLen = Len(" " & delCon & " ") if Right(posStr, chkLen) = " " & delCon & " " then posStr = Left(posStr, Len(posStr) - chkLen) end if posStr = " WHERE " & posStr dbCon.execute (delStr & posStr) delSql = ture end function ' ------------------------------------------------------------ ' Update Statement ' ------------------------------------------------------------ function updSql(tbName, setFd(), setVal(), delFd(), delVal(), delCon) updSql = false if (UBound(setFd) <> UBound(setVal)) or (UBound(delFd) <> UBound(delVal)) then response.write ("주어진 필드의 수와 입력 데이터의 수가 일치하지 않습니다.") exit function end if updStr = "UPDATE " & tbName setStr = "" for i = LBound(setFd) to UBound(setFd) setStr = setStr & setFd(i) & "=" & setVal(i) setStr = setStr & " ," next i setStr = RTrim(setStr) if Right(setStr, 1) = "," then setStr = Left(setStr, Len(setStr) - 1) end if setStr = " SET " & setStr 'if Length(GetTrim(setStr)) <= 10 then setStr = '' ' 뭐하는 코드지? 왜 setStr을 체크하지? posStr = "" for i = LBound(delFd) to UBound(delFd) posStr = posStr & delFd(i) & "=" & delVal(i) posStr = posStr & " " & delCon & " " next i posStr = RTrim(posStr) chkLen = Len(" " & delCon & " ") if Right(posStr, chkLen) = " " & delCon & " " then posStr = Left(posStr, 1, Len(posStr) - chkLen) end if posStr = " WHERE " & posStr dbCon.execute (updStr + setStr + posStr) updSql = ture end function %>출처 sql문 실행시키기 위한 function|작성자 혀니