Hello Folks!
I am using 2 separate SQL queries to accomplish a task and I was wondering I can combine these 2 queries into one more efficient query?
My database table may have more than one entry if queried by Telephone number.
I only want to extract the record information only if there is ONE occurrence by telephone number.
If there is more than one record with the same telephone number - then I do nothing.
So I have a jscript code snippet and this is how I am doing it right now BUT I am wondering if I can do this effeciently in a single query?
This code uses 2 SQL queries to accomplish this:
strSQL = "SELECT COUNT(*) FROM tblTelDir WHERE TelNum = \"5555551212\"";
objRs = objDB.Execute(strSQL);
intNumOccurrances = objRs.Fields(0).Value; //get number of entries for tel num
if (intNumOccurrances == 1) {
strSQL = "SELECT DisplayName, BldAddr, Office FROM tblTelDir WHERE TelNum = = \"5555551212\"";
objRs = objDB.Execute(strSQL);
strDNUser = objRs("DisplayName").Value;
strLoc = objRs("BldAddr").Value;
strOffice = objRs("Office").Value;
}
Thanks!!
I am using 2 separate SQL queries to accomplish a task and I was wondering I can combine these 2 queries into one more efficient query?
My database table may have more than one entry if queried by Telephone number.
I only want to extract the record information only if there is ONE occurrence by telephone number.
If there is more than one record with the same telephone number - then I do nothing.
So I have a jscript code snippet and this is how I am doing it right now BUT I am wondering if I can do this effeciently in a single query?
This code uses 2 SQL queries to accomplish this:
strSQL = "SELECT COUNT(*) FROM tblTelDir WHERE TelNum = \"5555551212\"";
objRs = objDB.Execute(strSQL);
intNumOccurrances = objRs.Fields(0).Value; //get number of entries for tel num
if (intNumOccurrances == 1) {
strSQL = "SELECT DisplayName, BldAddr, Office FROM tblTelDir WHERE TelNum = = \"5555551212\"";
objRs = objDB.Execute(strSQL);
strDNUser = objRs("DisplayName").Value;
strLoc = objRs("BldAddr").Value;
strOffice = objRs("Office").Value;
}
Thanks!!