I'm trying to execute the following SQL statement (built and tested in SQL Server 2005)
Select *
From mytesttable
where myPk in
(
select t3 from (
select field1, substring(field3, charindex(":", field3),6) t2, min(mypk) t3
from mytesttable
group by field2, substring(field3, charindex(":", field3),6)
) t
)
I know I can't use substring or charindex. So the innermost select looks like this in vbs:
strsql = "select mid(field3, instr(1, field3, ":")), min(mypk) from "
strsql = strsql & myCSVFileName
strsql = strsql & myCSVFileName & " GROUP By mid(field3, instr(1, field3, ":")) "
This runs fine.
But when I try to add the next select to wrap the most inner select, it fails. The code looks like this:
strsql = "select mypk from ( select mid(field3, instr(1, field3, ":")), min(mypk) from "
strsql = strsql & myCSVFileName
strsql = strsql & myCSVFileName & " GROUP By mid(field3, instr(1, field3, ":")) )"
The error message I get is that there is
No value given for one or more required parameters
Any suggestions? Thanks.