sql - How to select distinct values from one column in adodb recordset Excel VBA? -


I have a ADODB.Recordset rs that I'm getting from DB

  Mike Client John Manager Karen Client Who All Brian Manager  

Now I need to get all the titles, so I want to:

 < Code> Customer Manager sub  

I know that Rsphilter , but I'm not sure I can choose a different one from it.

In addition, I know that I can clone this recorcet:

  set rs_clone rs_clone as ADODB rs_clone = new ADODB.Recordset rs_clone = rs Getrows ()  

Is it possible to only clone different records? Or is there any better way? Thank you

A SQL string firing on the database gives you lots of room,

Small example (I like the output code while using late binding) where I'm asking for a separate list from the table column MyColumn

  dim Cn set the form of a blind rupee object cn = CreateObject ("ADODB.Connection") cn.Open strConn cn.CommandTimeout = 0 set RS = CreateObject ("ADODB.Recordset") set rs.ActiveConnection = cn ' 

strConn code> The correct connection is required to be set to string.

Edit

A sql The following solution has been found on the string on the database with the help of this post.

If you prefer the initial bond, the context of the following will be required:

  • Microsoft Acti VeX Data Objects (using the 6.1 6.1 library)
  • The Microsoft Scripting Runtime (this is how we can use a dictionary)

The code is as follows:

  options clear global structure string such as strCon = _ "PROVIDER = MySQLprovider;" & Amp; _ "P * SSWORD = MyPword;" & Amp; _ "USER ID = MyLogin;" & Amp; _ "Initial catalog = maidi;" & Amp; _ "Data Source = MyServer;" & Amp; _ "Process to prepare = 1;" & Amp; _ "Auto translate = true;" Sub getDistinctRecords () Dim cn ADODB.Connection set cn = as new ADODB.Connection cn.ConnectionTimeout = 0 cn.Open strConn RED ADODB.Recordset set = new ADODB.Recordset rs.ActiveConnection = cn '& gt; & Gt; Duplicate your record set with this non-specific member. Open _ "SELECT" as a 'MyCol UNION ALL' & amp; _ "Select" as a 'MyCol Unions ALL' & amp; _ "SELECT 'b' as MyCol UNION ALL '& amp; _ Arrival ()" Select "B" as MyCol "as the version Arrival = rs.GetRows () dims as Scripting. Dictionary set d = new scripting.Dictionary dim I am (i.e., ar) 2 (ar (2, d) (ar (0, ii)) = 1 forward to i For each v, there is a variable array of '' myArray. '& Gt; & gt; D.Key () unique values.' & Gt; & gt; v it will be repeated through each of them '& Gt ;> To print Print on instant window debug.print g next V '=====================' resume error on clean-up connection Next Set RS ActiveConnection = Error But nothing gott 0 then (but nothing is nothing) then then (rs.State and 1) = 1 then rs.Close set = no end to nothing (cn is nothing), then then ( Cn.State and 1) = 1 then cn. Set cn = nothing end if end sub  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -