sql - Select max visual studio 2010 -


i'm updating program visual basic 6 visual studio 2010 and, of course, have founded lot of problems solve.

i'm using access database 4 tables same key (indice).

if use code follow, can last record coddekafix table:

private sub cmdlast_click(byval sender system.object, byval e system.eventargs) handles   cmdlast.click     dim con new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=c:\dekafix\consulta dekafix\dekafix.mdb")     dim cmd new oledbcommand()     con.open()     sql = "select * indice coddekafix=(select max(coddekafix) indice)" 

but if want results tables same key (indice) change showed below program doesn't work.

sql = "select * indice, dekafix1, dekafix2, dekafix3" _       & " coddekafix=(select max(coddekafix) indice) and" _       & " indice.coddekafix = dekafix1.coddekafix and" _       & " dekafix1.coddekafix=dekafix2.coddekafix and" _       & " dekafix2.coddekafix=dekafix3.coddekafix and" _       & " order indice.coddekafix" 

your sql code in second code sample invalid. when strip out formatting representing string in vb code, this:

select * indice, dekafix1, dekafix2, dekafix3 coddekafix=(select max(coddekafix) indice) , indice.coddekafix = dekafix1.coddekafix , dekafix1.coddekafix=dekafix2.coddekafix , dekafix2.coddekafix=dekafix3.coddekafix , order indice.coddekafix 

you have 2 problems here:

1) there's "and" before order clause. remove it.

2) first line of clause has ambiguous reference coddekafix -- need specify table that's coming from. replacing coddekafix indice.coddekafixshould trick.

sql = "select * indice, dekafix1, dekafix2, dekafix3" _   & " indice.coddekafix=(select max(coddekafix) indice) and" _   & " indice.coddekafix = dekafix1.coddekafix and" _   & " dekafix1.coddekafix=dekafix2.coddekafix and" _   & " dekafix2.coddekafix=dekafix3.coddekafix" _   & " order indice.coddekafix" 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -