Link to home
Start Free TrialLog in
Avatar of SiHodgy007
SiHodgy007Flag for United Kingdom of Great Britain and Northern Ireland

asked on

VBA Vbscript Issue

Hi,

I'm trying to add a 'String' to the end of a SQL statement assigned a variable called SQL but it fails because of the parenthesis.

SQL = SQL & "'String'"

Any ideas?
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try
sql = IIf(Right(sql, 1) = ")", Replace(sql, ")", " 'String')", Len(sql) - 1), sql & " 'String'")

Open in new window

Regards
Avatar of SiHodgy007

ASKER

That works, no idea how.

Is there a way now to replace the string with a variable that contains a string?
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome can you just explain the logic of the statement?
if last char is ) then replace the  ) with 'string' ) else add 'string' at the end of text
Sorry just trying to get the logic in my head, if I knew there wasn't a ) what would the code look like?
sql = sql & " '" & String& "'"
That's right
but corrected code for the other possibility
strString = "String"
sql = IIf(Right(sql, 1) = ")", Left(sql, Len(sql) - 1) & " '" & strString & "')", sql & " '" & strString & "'")

Open in new window

Thanks