我想從Excel中的值在單元格中創建一個SQL查詢。但從我複製單元格並粘貼到任何窗口時,它會給我雙引號。有什麼辦法可以消除這一點。當從Excel複製粘貼到記事本給出雙引號
Range("H16").Value = "Select distinct(description), merchant_name from(" & vbCrLf & "select distinct description, merchant_name from table_phase" & Range("G3").Value
Range("H16").Value = Range("H16").Value & vbCrLf & patternString & vbCrLf & "Union all" & vbCrLf
Range("H16").Value = Range("H16").Value & "select distinct description, merchant_name from table_phase" & Range("G4").Value
Range("H16").Value = Range("H16").Value & vbCrLf & patternString & vbCrLf & ") order by merchant_name, description"
Range("H16").Value = Trim(Range("H16").Value)
Range("H16").WrapText = True
Range("H16").Select
Selection.Copy
範圍G4和G3 contins號碼,如24或25所述的圖案列包含: 其中MERCHANT_NAME在(「值1」,「值2」)
我已產生的模式串這樣
patternString = "where merchant_name in ("
For i = 1 To UBound(addedMerch, 1) - 1
patternString = patternString & " '" & addedMerch(i, 1) & "',"
If (i - (4 * (i \ 4))) = 0 Then
patternString = patternString & vbCrLf
End If
Next
如果圖案太多,我已經使用了下一行字符。我想在不同線路的SQL查詢,以避免混淆
的[從細胞複製時漏下引號(http://stackoverflow.com/questions/24910288/leave-out-quotes-when-copying-from-cell) – Vasily