0

Suppose I have a Querystring defined as follows:

String MyTableCount =  "SELECT"
                         + "COUNT(*) AS TOTALCOUNT "
                         + " FROM "
                          // and so on 

How do I access the "TOTALCOUNT" value as I want to compare it's value to another value?

I was thinking something like the following:

if((MyTableCount.TOTALCOUNT) > 100 )
{

}

else
{

}

But this generates an error, as TOTALCOUNT variable needs to be defined.

3
  • 1
    I'm not sure if I understand your question correctly, but are you actually running your database query against the Database using a connection, statement, and ResetSet? If so you can pull the data from the ResultSet and store it to access it. Commented Mar 21, 2014 at 18:43
  • Oh, yeah, you are right, I shall look at that option. Commented Mar 21, 2014 at 18:44
  • MyTableCount.TOTALCOUNT does not make sense. MyTableCount is your query string, which you should pass to one of the query execution methods. Commented Mar 21, 2014 at 18:46

1 Answer 1

3

You need to print out the query string. According to what you have, it starts as:

SELECTCOUNT(*) AS TOTALCOUNT

This is not a recognized SQL command. You need a space after the SELECT.

Sign up to request clarification or add additional context in comments.

5 Comments

Agreed. Staying away from unnecessarily concatenating your queries would avoid issues like this.
@TinyHaitian Did you mean to stay that I should write the full query in one line?
@Gordon Linoff Your answer sounds more towards correcting the SQL String rather than what I actually asked. May I know why? Anyways, thanks for your answer.
@John . . . If the SQL string is not formatted correctly, it will not run. If it doesn't run, you cannot get results from it.
@John, that what I would do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.