Your example looks like a C# statement although it is syntactically incorrect since there is no operator in the statement. In my solution below, I added a declaration for a
string
named
mySQLStatement
and an assignment to that statement of the concatenated strings that you included in your question. The result is that
mySQLStatement
contains a syntactically correct SQL Statement. I know that is true because I created a table and ran the statement against it.
string mySQLStatement = "select SUM(dramount)-SUM(cramount)" +
"from GlTransaction where Accountno like'1%' select SUM(dramount)-SUM(cramount)" +
"from GlTransaction where Accountno like'2%'" +
"select SUM(dramount)-SUM(cramount)" +
"from GlTransaction where Accountno like'3%'" +
"select SUM(dramount)-SUM(cramount)" +
"from GlTransaction where Accountno like'4%'" +
"select SUM(dramount)-SUM(cramount)" +
"from GlTransaction where Accountno like'5%'";
After executing the above statement the contents of mySQLStatement will be
"select SUM(dramount)-SUM(cramount)from GlTransaction where Accountno like'1%' select SUM(dramount)-SUM(cramount)from GlTransaction where Accountno like'2%'select SUM(dramount)-SUM(cramount)from GlTransaction where Accountno like'3%'select SUM(dramount)-SUM(cramount)from GlTransaction where Accountno like'4%'select SUM(dramount)-SUM(cramount)from GlTransaction where Accountno like'5%'"
Your SQL statement will create five result sets. While that will work, it may not be the simplest way to retrieve this data. I recommend that you modify your SQL statement to return just one result set with a separate column for each value rather than five result sets of one column each.
Maybe that's not what you really want to do.... You may want to clarify your question using the
Improve Question button above and explain what you are trying to accomplish (using an example of what you want the result to look like).