I'm trying to create a SQL query in a cell from the values in excel. But from when I copy the cell and paste in any window it gives me double quotes. Is there any way to remove this.
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
The range G4 and G3 contins numbers like 24 or 25. The pattern string contains : where merchant_name in ( 'Value1','Value2' )
I have generated the pattern string like this
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
I have used the next line character to if the patterns are too many. I want to get the SQL query at different lines to avoid confusion