Page 1 of 1

Apostrophe question in SQL statement

Posted: Tue May 22, 2012 9:50 pm
by ymc
The issue is about the (') apostrophe in the coding inside the report.
I have created a form with a Checked List box to gathering the parameters in the report designer. Then when the user checked some of the options, I have some C# code to formulate the checked items to be a string, e.g. StationstrCollected as a Variable inside the report designer, to store the string in order to pass to SQL statement for query.

Sample:
ABC
DEF
GHI

3 items have been checked and the string formulate as StationstrCollected = ABC,DEF,GHI.

However, in the SQL statement would like to make it as - where Station in (@StationstrCollected). Therefore, I need to massage the content to be 'ABC','DEF','GHI'.
I have a loop to add the (') apostrophe to those checked items to formulate the pattern as ABC','DEF','GHI (the prefix ' and suffix ' will be added by system automatically). When looking at the final result the parameter StationstrCollected becomes 'ABC'',''DEF'',''GHI' that the (') apostrophe becomes twice.

I have tried revise the coding from simply add the (') apostrophe to \' or \u0027 and still no luck to get a single ' to retrieve the expected result.

Anyone got idea how to make it?

Apostrophe question in SQL statement

Posted: Wed May 23, 2012 7:19 am
by Alex K.
Hello,

Please try to use the following query:
select * from MyTable where MyField1 in ({Var1})

where Var1 it is string variable and get the next value:
'ABC', 'QWE'

Thank you.