Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help with simple sql query

awyeahawyeah Member Posts: 2
Hello,

I am trying to do some data filtering using sql query, but cannot find the correct logic for implementation. Currently I am thinking to use sql to integrate all things into a sql line and execute it:

(1) Select entire table from excel worksheet
(2) Remove the rows in the table corresponding to duplicates in the CustomerNo column
(3) Remove the blank lines in the excel file (where there is no CustomerNo)

I have found a way to execute (1) and (3):

[code]
'Do not copy empty rows at the end of the excel file
'(1) sqlstr = "Select * from [" & xlSName & "$]"
'(3) sqlstr = "DELETE FROM " & sqlstr & " WHERE CustomerNo IS NULL"

'Opening Sheet in Excel Sheet Like a Table
rec.Open " & sqlstr & ", cn, adOpenKeyset
[/code]

For 2, if anyone can give me a starter, id be delighted. I am still brainstorming the use of sql select for this type of filtering.. Example of (2) how it should be like:

[quote]
Input table: Table_1
--------------------------------------------------------------------
StnCode CustomerNo Name1 Name2
0121 00200002 HARWANT REALTY SDN BHD (G.S. GILL)
0121 00200003 EUROPE KITCHEN STATION SDN BHD 168
0121 00200004 COLISEUM CAFE & HOTEL
0121 00200005 SKT V K KALYANASUNDRAM SDN BHD (KOWLOON)
0121 00200006 MAJLIS AMANAH RAKYAT (M.A.R.A)
0121 00200006 MAJLIS RAKYAT SDN
0121 00200007 F T LAND SDN BHD
0121 00200008 CYCLE & CARRIAGE BINTANG BHD.
0121 00200010 YAYASAN UBAIDI (MYDIN)
0121 00200011 MALAYAN BANKING BHD.


Output: Table_2
--------------------------------------------------------------------
StnCode CustomerNo Name1 Name2
0121 00200002 HARWANT REALTY SDN BHD (G.S. GILL)
0121 00200003 EUROPE KITCHEN STATION SDN BHD 168
0121 00200004 COLISEUM CAFE & HOTEL
0121 00200005 SKT V K KALYANASUNDRAM SDN BHD (KOWLOON)
0121 00200007 F T LAND SDN BHD
0121 00200008 CYCLE & CARRIAGE BINTANG BHD.
0121 00200010 YAYASAN UBAIDI (MYDIN)
0121 00200011 MALAYAN BANKING BHD.
[/quote]

i.e. if any duplicates (or more than 2) are found in CustomerNo column, remove the rows in the table corresponding to those duplicates in the CustomerNo column.

Sign In or Register to comment.