-1

I'm getting an error stating that say column doesnt belong to table. Here is my query below, its pretty straight forward.

query = " SELECT A.COLUMN "
        " FROM TABLE_1 A, TABLE_2 B"
        " WHERE A.COLUMN = B.COLUMN "

For simplicity sake, I put it into a dataset and do a for loop and it works fine. By the way tested query in management studio and it all works fine.

This is where have the problem:

dim new_val as string

new_val = row("A.COLUMN") 'ERROR

NOTE: When i change my query to :

SELECT A.COLUMN **AS COLUMN1** 

and then:

new_val = row("COLUMN1") it works.

Does anyone know the reason for this?? Also forgot to note that some columns have the same name thats why i use A.COLUMN.

Will
  • 1,084
  • 5
  • 20
  • 42
  • It's worth noting that you're using SQL-89 syntax for your joins which was deprecated (amongst other reasons) for ambiguity on complex joins. You should start using the syntax described by @LittleBobbyTables - See [this question](http://stackoverflow.com/questions/334201/why-isnt-sql-ansi-92-standard-better-adopted-over-ansi-89) for more info – Basic Jul 20 '12 at 16:02

2 Answers2

2

Just use:

new_val = row("COLUMN") 

There is no reason to have the table suffix in your reference, just the column name.

Also, you really should re-write your query to use INNER JOINS:

query = " SELECT A.COLUMN "
    " FROM TABLE_1 A INNER JOIN TABLE_2 B ON A.COLUMN = B.COLUMN "
LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
-1

I would suggest that you set the breakpoint in the problematic line and check the name of the column in the quick watch window. In this case, you will be able to determine the column name and thus adjust your code.

platon
  • 5,310
  • 1
  • 22
  • 24