ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

¨â²Õ¼Æ­È¥h°£­«½Æªº¸ê®Æ«á±Æ§Ç

¦^´_ 3# hcm19522


Sub ¥h­«±Æ§Ç()
With CreateObject("adodb.connection"): V = Application.Version
If V >= 12 Then V = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0; "
If V < 12 Then V = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0; "
.Open V & "Data Source=" & ThisWorkbook.FullName

Set s = Sheets("¤u§@ªí1")
s.Columns(4).ClearContents
s.Rows("1:1").Insert Shift:=xlDown
s.Range("a1:b1") = Array("a", "b")
q = "select a as a from [¤u§@ªí1$A1:A] " & vbCrLf & " union all "
q = q & vbCrLf & " select b as a from [¤u§@ªí1$B1:B]"
q = "select distinct a from (" & q & ")  order by a "
s.Range("d2").CopyFromRecordset .Execute(q)
s.Rows("1:1").Delete: End With
End Sub

sql¥h­«±Æ§Ç.zip (18.18 KB)

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-3-21 23:16 ½s¿è

¦^´_ 7# henry860608

­Õ­Y¨S¾Ç¹LSQL ¥i¥Hª½±µ¸õ¹L ¨Ï¥Î¨ä¥L¤j¤jªº¸Ñªk¤ñ¸û¤è«K ¾Ç²ß¸ô½u¤]¤ñ¸û¥¿³W

¥t¥~¨Ï¥Î¦¹¤èªk³£»Ý­n¦w¸Ë .Framework 3.5
¥]¬Aq¤jªºarraylist

¥H¤U¸ÑÄÀq­È¤¤,SQL»yªk¸ÑÄÀ

select distinct a from
(select a as a from [¤u§@ªí1$A1:A]
union all
select b as a from [¤u§@ªí1$B1:B] )  
                                                                order by a



1.
Àò¨ú¤u§@ªí1¤¤ªºAÄæ¸ê®Æ
select a as a from [¤u§@ªí1$A1:A]

¦X¨Ö
union all

¤u§@ªí1¤¤ªºBÄæ¸ê®Æ
select b as a from [¤u§@ªí1$B1:B]


2.
select distinct a from      '±N1.³¡¤ÀÀò¨ú¾ã²z¦nªº¸ê®Æ distinct¥h­«
(select a as a from [¤u§@ªí1$A1:A]
union all
select b as a from [¤u§@ªí1$B1:B] )  
                                                                order by a    '¨Ã¥Border by±Æ§Ç


­Y§A¹ïSQL¦³¿³½ì ±q2019¦~«á,§K¶Oºô¸ô½Òµ{«D±`¦h ¤×¨äB¯¸¤W ±q¹s¶}©l¾Ç ¤j·§2~3­Ó¤ë´N¥i¥H
¯u¥¿·N¸q¤W¨Ã¤£¬O®³¨Óµ¹excel³æ¿W¥Îªº
¥u¤£¹L­è¦n¥i¥H®³vba°V½m»yªk  ¹ê»Ú¥Î¦bSQL server »Pvba¤W
­±¹ï²{¹êªº°ª­t²ü³õ´º,¶W¹L30000µ§¥H¤Wªº¸ê®Æ ©ÎªÌ¦hªí¾ã¦X ´N¬OSQLªº¸nªù
¤×¨ä¦b¤ººô¤¤ ¦h¥x¹q¸£ ¶i¾P¦s ©ÎªÌ±µª¦ÂΤW³£¦³«Ü±j¤jªº«K§Q©Ê  ¦Ó¥B¤£¥Î¾á¤ß ¸ê®Æ½s½X²§±` ¤ñ¦p"温" "羣" ³oÃþexcel ·|²§±`ªº¤å¦r
·íµM¥¼¨Ó¤]¯à¹B¥Î¨ìptSQL ©ÎªÌMySQL

TOP

        ÀR«ä¦Û¦b : ÀR§¤±`®¦¤v¹L¡B¶¢½Í²ö½×¤H«D¡C
ªð¦^¦Cªí ¤W¤@¥DÃD