I'm not really sure what you're trying to achieve here, but instead of having a sub query, could you replace it with an inner join? Refer to the table in the first From statement as a (for example), and the second table as b.

eg:

Code:
sql1 = "SELECT Distinct(TraceID) FROM Trn_SO_Details a 
Inner Join Trn_SO b 
on a.TraceId = b.TraceId 
WHERE a.SODt='" + InvtDt + "' AND a.ProdCode='" + ProdCode + "' " 'a.TStatus Not IN('Processed','PROCESSED') AND T.ErrorType Not IN('Duplicate')"
sql1 &= " AND  b.Status NOT IN('Processed','PROCESSED') AND a.ErrorType Not IN('Duplicate')) "
                objDB.OpenDataSet(ds, sql1)
                ds.Tables(0).TableName = "InvtDetails"
Where did the T.ErrorType come from or is this a typo?

HTH

JP