sql server - Delete if record exists and Insert if record doesn't exist -
in loop, i'm writing insert , delete query following:
in case if checkbox not check check if record exist & if exist delete. if doesn’t exist don’t anything.
if checkbox check check if record exist & if exist don’t if doesn’t exist insert it.
i need check on whether queries, subqueries execute or return error because i'm writing without wanting change database right now.
for each odatagriditem in valgrid2.items chk = odatagriditem.findcontrol("checkbox1") rn = odatagriditem.findcontrol("lblrptname") rid = odatagriditem.findcontrol("lblreportid") if chk.checked = true rpti = ctype(odatagriditem.findcontrol("lblreportid"), label).text 'valsql2 = "insert companyreportlisttable(companyid, reportid) values (valcompanyid, rpti) not exists(select * companyreportlisttable reportid <> rpti , companyid <> valcompanyid , " & chk.checked & "= 1)" 'if exists don’t 'valsql2 = valsq2 & ";if reportid = rpti , companyid = valcompanyid begin companyid = companyid , reportid = reportid end" 'to nothing, i'd equal parameter's value column name count += 1 rptn = ctype(odatagriditem.findcontrol("lblrptname"), label).text oexargs.add(rptn) response.write(rpti + " - " + rptn + "<br/>") else 'valsql2 = valsq2 & ";delete companyreportlisttable exists(select * companyreportlisttable reportid = rpti , companyid = valcompanyid and" & chk.checked & " = 0)" 'if doesn't exist don’t 'valsql2 = valsq2 & ";if reportid <> rpti , companyid <> valcompanyid begin companyid = companyid , reportid = reportid end" end if
valsql2 = "insert companyreportlisttable(companyid, reportid) values (valcompanyid, rpti) not exists(select * companyreportlisttable reportid <> rpti , companyid <> valcompanyid , " & chk.checked & "= 1)"
in code " & chk.checked & "= 1)"
will give error . true =1 not support in sql .
Comments
Post a Comment