Excel Ado sql concatenate queries -
now count if "br" in cell with
query 1 sql activeworkbook.fullname, "select " & _ " trim(`f1`), " & _ " sum(iif( trim(`f1`) null ,1,1)), " & _ " sum(iif(`f2` in ('sk','tp'),1,)), " & _ " sum(iif(`f2` in ('br'),1,)), " & _ " sum(iif(`f2` in ('pg'),1,)), " & _ " sum(iif(`f2` in ('rin'),1,)) " & _ " [sh1$] " & _ " grouping trim(`f1`) " & _ " order trim(`f1`) asc ", worksheets("sh1").range("e6"), "no", 1
but not unique count of "br" contains cell
distinct count query, if f2 contains "br" , f4 not contain "-" , not blank count f4
query 2 sql activeworkbook.fullname, "select " & _ " sum(iif(`f2` in ('br') , `f4` not in ('','-'),1,)) c " & _ " ( " & _ " select distinct `f4`, `f2` " & _ " [sh1$] ) tmp " & _ " grouping `f4` " & _ , worksheets("sh1").range("h6"), "no", 0
but how can concatenate thoose queries in 1 query? set query2 instead of query 1
" sum(iif(`f2` in ('br'),1,)), " & _ field
code:
sub sql(sourcefile variant, sqlstr string, pasterng range, yesno string, imex byte) dim con object dim rstdata object dim sdatabaserangeaddress string set con = createobject("adodb.connection") set rstdata = createobject("adodb.recordset") if imex = 1 imexx = "imex=1;" else imexx = "" con.open "provider=microsoft.ace.oledb.12.0;data source=" & sourcefile & ";extended properties = ""excel 12.0 macro;" & imexx & "hdr=" & yesno & """;" rstdata.open sqlstr, con, 1, 1, 1 pasterng.copyfromrecordset rstdata rstdata.close set rstdata = nil set con = nil end sub
sql excel vba excel-vba ado
No comments:
Post a Comment