views:

21

answers:

2
Field = "columnName"
value = '2,4' 
query = ""&Field&" in("&value&")"

here the query will be : columnName in('2,4')

but i want it to be : columnName in(2,4)

how to remove the single quotes

Please help ASAP

A: 

If you know that there always is apostrophes around the value, you can simply get the characters between them:

query = Field & " in (" & Mid(value, 2, Len(value) - 2) & ")"

If you know that the vales are numerical (i.e. doesn't need any apostrophes in the SQL because they aren't string literals), you can remove all apostrophes in the value:

query = Field & " in (" & Replace(value, "'", "") & ")"

You might also consider where the apostrophes comes from in the first place. If you add them at some point earlier in the code, the easiest would of course be to not add them (or preserve the original value in a different variable if you need the apostrophes for something else).

Guffa
+1  A: 

This will do.

Field = "columnName"
value = '2,4' 
query = ""&Field&" in("& Replace(value, "'", "") &")"
AnthonyWJones