Apostrophe question in SQL statement

Stimulsoft Reports.NET discussion
Post Reply
ymc
Posts: 31
Joined: Tue Oct 30, 2007 9:00 pm
Location: Hong Kong

Apostrophe question in SQL statement

Post 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?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Apostrophe question in SQL statement

Post 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.
Post Reply