sql - vbnet select inside a select to a dt -


i got little code connect db, select data , write data file.

...

sqlquery = ("select field1 asl, field2 ncuen , field3 nfac , "" contr [2016cl]")  using connection sqlconnection = new sqlconnection("server=" & srvsql & ";database=" & bdsql & ";uid=" & usrsql & ";password=" & pswsql & ";")     connection.open()     using comm sqlcommand = new sqlcommand(sqlquery, connection)         dim rs sqldatareader = comm.executereader         dim dt datatable = new datatable         dt.load(rs)          call clcreatecsv.createcsvfile(dt, strfilenamediario)     end using     connection.close() end using 

.....

public shared sub createcsvfile(dt datatable, strfilepath string)     dim sw new streamwriter(strfilepath, false, encoding.utf8)     dim icolcount integer = dt.columns.count      each dr datarow in dt.rows         integer = 0 icolcount - 1             if not convert.isdbnull(dr(i))                 sw.write(dr(i).tostring())             end if             if < icolcount - 1                 sw.write(";")             end if         next         sw.write(sw.newline)     next     sw.close() end sub 

i need fill 4th value on select ("" contr) field table joins middle table.

field3 joins table on gfac.gfac2 table gfac joins 3rd table on ccli.ccli1 --> this 1 need on query

could use inner join but, afaik fields validate join.

how can this, writing all data [2016cl] , field contr each 1 of them if exists?

thanks in advance. if need more info, ask!

use left join instead inner join.

for example: select * table1 left join table2 on ...

that query selects rows table1. if row in table1 doesn't have match record in table2, table2 fields contains null.

hope helps.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -