-1

I Have a list of My SQL files with the following names. These are located in a folder whose path is reportconnection (reportconn)

 TableName
 A1_1
 A1_2
 A1_3
 A1_4
 A1_5
 A1_6
 A1_7
 A1_8

Each of these tables consists of data regarding 1 e mail campaign blast.

The structure of each of these is as follows. There are 8 such tables, one for each e mail campaign

    C1  C2  C3
    Y   X   Z
    Y2  X2  Z2

I want a list of unique counts of C2 for each A1, A2, A3 etc. I have used the following code

   C2count<-list()

 For (I in(Tablenames){
  sql2 <- paste("select count(DISTINCT BINARY C2) from ", TableName)## SQL 
 Query
 C2count<-rbind(C2count,dbGetQuery(reportconn, sql2).}

I am getting just a single list of values. Please help me.

Vishnu Raghavan
  • 83
  • 1
  • 10

1 Answers1

1

Your sql2 is pasting in "Tablenames" instead of I. I is looping through each name in your list of Tablenames. I is what is changing each time. Hope this helps.

` C2count<-list()

 For (I in Tablenames){
     sql2 <- paste("select count(DISTINCT BINARY C2) from ", I)## SQLQuery
     C2count<-rbind(C2count,dbGetQuery(reportconn, sql2)
}`
Charlie
  • 61
  • 3