Suppose I have the following 3 SQL queries in an ASP code where the 3rd query makes use of the 1st two queries:
strSQL1="SELECT DISTINCT(adet.ErnCode) FROM ADET AS adet,ERNMST AS ern WHERE adet.ErnCode=ern.ErnCode AND ern.ErnDed='E'"
strSQL2="SELECT DISTINCT(adet.ErnCode) FROM ADET AS adet,ERNMST AS ern WHERE adet.ErnCode=ern.ErnCode AND ern.ErnDed='D'"
This is the 3rd query that makes use of the above 2 queries:
strSQL3="SELECT DISTINCT(em.ECode),em.EName,"
Do Until(objRS1.EOF AND objRS2.EOF)
strSQL3=strSQL3 & "(SELECT adet.Amt FROM ADET AS adet
WHERE adet.ErnCode='" & objRS1("ErnCode"
& "' AND
adet.ECode=em.ECode) AS '" & objRS1("ErnCode"
& "1E',
(SELECT adet.Amt FROM ADET AS adet WHERE adet.ErnCode=
'" & objRS2("ErnCode"
& "' AND adet.ECode=em.ECode)
AS '" & objRS2("ErnCode"
& "2D',"
objRS1.MoveNext
objRS2.MoveNext
Loop
strSQL3=strSQL3 & " FROM.........................."
strSQL3=Replace(strSQL3,", FROM"," FROM",1)
Now as long as the RecordCount of strSQL1 & strSQL2 remains the same, there is no problem but if they are not the same, the 3rd query will throw an error since I have used the keyword AND in Do Until(objRS1.EOF AND objRS2.EOF). For eg. if the RecordCount of strSQL1 is 7 & that of strSQL2 is 8, then an error will be thrown. One way of avoiding this is by replacing AND with OR but if I do so, the last field in strSQL2 will be neglected since objRS1 has already reached its EOF. Is there some way I can ensure that even if the RecordCount of strSQL1 & strSQL2 are not the same, I can still make use of AND in the statement Do Until(objRS1.EOF AND objRS2.EOF) so that none of the fields in strSQL2 get neglected & at the same time, an error isn't thrown?
Thanks,
Arpan
strSQL1="SELECT DISTINCT(adet.ErnCode) FROM ADET AS adet,ERNMST AS ern WHERE adet.ErnCode=ern.ErnCode AND ern.ErnDed='E'"
strSQL2="SELECT DISTINCT(adet.ErnCode) FROM ADET AS adet,ERNMST AS ern WHERE adet.ErnCode=ern.ErnCode AND ern.ErnDed='D'"
This is the 3rd query that makes use of the above 2 queries:
strSQL3="SELECT DISTINCT(em.ECode),em.EName,"
Do Until(objRS1.EOF AND objRS2.EOF)
strSQL3=strSQL3 & "(SELECT adet.Amt FROM ADET AS adet
WHERE adet.ErnCode='" & objRS1("ErnCode"
adet.ECode=em.ECode) AS '" & objRS1("ErnCode"
(SELECT adet.Amt FROM ADET AS adet WHERE adet.ErnCode=
'" & objRS2("ErnCode"
AS '" & objRS2("ErnCode"
objRS1.MoveNext
objRS2.MoveNext
Loop
strSQL3=strSQL3 & " FROM.........................."
strSQL3=Replace(strSQL3,", FROM"," FROM",1)
Now as long as the RecordCount of strSQL1 & strSQL2 remains the same, there is no problem but if they are not the same, the 3rd query will throw an error since I have used the keyword AND in Do Until(objRS1.EOF AND objRS2.EOF). For eg. if the RecordCount of strSQL1 is 7 & that of strSQL2 is 8, then an error will be thrown. One way of avoiding this is by replacing AND with OR but if I do so, the last field in strSQL2 will be neglected since objRS1 has already reached its EOF. Is there some way I can ensure that even if the RecordCount of strSQL1 & strSQL2 are not the same, I can still make use of AND in the statement Do Until(objRS1.EOF AND objRS2.EOF) so that none of the fields in strSQL2 get neglected & at the same time, an error isn't thrown?
Thanks,
Arpan