Hi All, I am working on write Sql in VBA and I want to save this query into a array table. Since I will change my Sql later,so the array size can not be defined now. I haven't done any code with array before, can anyone give me some example or hints on how to do that? Thanks!
So an example of my problem is that I have an initial selection query with 6 columns, and I need to develop a new query which contains the first 3 columns from the initial query, and the rest field is depend on my sql.
the first sql is to check the 4th columns from the initial query, for any data not contain "NA" in the 4th column, it will be added to the new query,
the second sql is for any data = "NA" in the 4th column of the initial query and "B2" in the third column, first step is to check if there is any "B2" in the entire 3rd column, if there the count of "B2" in the 3rd column is larger then 1 (eg.2), change the entire 4th column to the 3rd column. If there is only one "B2" in the 3rd column (eg.1), then copy "B2" into column 4,5,6 in the same row only.
Here is the examples:
Initial query (eg.1)
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 NA NA NA
3 A3 B3 C3 D3 NA
.....
New Query
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 B2 B2 B2
3 A3 B3 C3 D3 D3
...
Initial query (eg.2)
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 NA NA NA
3 A3 B2 C3 D3 NA
.....
New Query
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 B2 B2 B2
3 A3 B2 B2 B2 B2
...
So I need to develop a loop for check all the rest columns in the original table, and my supervisor told me to do this by using array, so I just wandering if anyone can give me some direction for how to develop an array to pass these sqls in VBA? [highlight red]Or[/highlight] any other efficient way would work in my case? Thanks!
So an example of my problem is that I have an initial selection query with 6 columns, and I need to develop a new query which contains the first 3 columns from the initial query, and the rest field is depend on my sql.
the first sql is to check the 4th columns from the initial query, for any data not contain "NA" in the 4th column, it will be added to the new query,
the second sql is for any data = "NA" in the 4th column of the initial query and "B2" in the third column, first step is to check if there is any "B2" in the entire 3rd column, if there the count of "B2" in the 3rd column is larger then 1 (eg.2), change the entire 4th column to the 3rd column. If there is only one "B2" in the 3rd column (eg.1), then copy "B2" into column 4,5,6 in the same row only.
Here is the examples:
Initial query (eg.1)
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 NA NA NA
3 A3 B3 C3 D3 NA
.....
New Query
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 B2 B2 B2
3 A3 B3 C3 D3 D3
...
Initial query (eg.2)
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 NA NA NA
3 A3 B2 C3 D3 NA
.....
New Query
c1 c2 c3 c4 c5 c6
1 A1 B1 C1 D1 E1
2 A2 B2 B2 B2 B2
3 A3 B2 B2 B2 B2
...
So I need to develop a loop for check all the rest columns in the original table, and my supervisor told me to do this by using array, so I just wandering if anyone can give me some direction for how to develop an array to pass these sqls in VBA? [highlight red]Or[/highlight] any other efficient way would work in my case? Thanks!