Question

The below code is one of the part in big project.

Below code counts records in the particular column.

   Sub qareportds()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sname As String
    Dim i As Integer
    Dim lrow As Integer

    sname = ActiveSheet.Name
    Set con = New ADODB.Connection
    Set rs = New ADODB.Recordset
    value1 = weeknum

    con.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & ActiveWorkbook.FullName

    If con.State = adStateClosed Then con.Open

    Dim query1 As String

    query1 = "SELECT COUNT(RETAIL_SKU) FROM [RETOUCH$]"

    rs.Open query1, con, adOpenKeyset, adLockOptimistic

    Sheets("SHEET3").Range("a1").CopyFromRecordset rs

    rs.Close

    Set rs = Nothing
    Set con = Nothing
    End Sub

Now i need to count the distinct values in the column .I used the below query

query1 = "SELECT COUNT(distinct RETAIL_SKU) FROM [RETOUCH$]"

But it throws below error ..

odbc driver does not support the requested properties

Update Section:

Is it possible to insert this query-

SELECT COUNT(A.RETAIL_SKU) AS TotalCount FROM (SELECT DISTINCT RETAIL_SKU FROM [RETOUCH$]) AS A)

into this

SELECT  REGION + '-' + STUDIO_SHORT_NAME,
    AVG(WorkedHours),
    AVG(OVERALL_CYCLE_TIME_HRS),
    'Studio Retouch - By Studio Locations - Non IA' as value1,
    13 as date1 
FROM    [RETOUCH$] 
WHERE   RETOUCH_LEVEL IN (1,2,3,4,5,6) 
    AND MERCHANT='Amazon' 
    AND SOURCE_TYPE='Studio' 
GROUP   BY REGION + '-' + STUDIO_SHORT_NAME
Was it helpful?

Solution

It's because COUNT(DISTINCT ...) is not yet supprted. Try,

SELECT COUNT(A.RETAIL_SKU) AS TotalCount
FROM
(
    SELECT DISTINCT RETAIL_SKU 
    FROM [RETOUCH$]
) AS A
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top