Solved

How to Detect True Value in SQL statement written In VC++

Posted on 1998-11-30
4
173 Views
Last Modified: 2011-09-20
Hello Experts,

I need your advice a bit. I wrote a program in VC++ which used ODBC driver to connect database to SQL Server. However, I need to write a select statement to select only the item that is true. Eg is shown below :

DATABASENAME : TBLITEMCODE
FldItemCode     String (Database field In SQLSERVER)
Check           Boolean (Database field In SQLSERVER)

My SELECT statement (to select only for Check = True) is shown as below :

strcpy(statement, "SELECT * FROM TBLITEMCODE WHERE CHECK = *<what should I put here for true value> ")

* if true/false value please let me know what is the value

Yur help will be much appreciated

Dekoay
0
Comment
Question by:dekoay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 50 total points
ID: 1178928
Your SQL statement should be:

a) For True values
SELECT * FROM TBLITEMCODE WHERE CHECK

b) For False values
SELECT * FROM TBLITEMCODE WHERE NOT CHECK

Thanks
pagladasu
0
 

Expert Comment

by:Gawande
ID: 1178929
In above condition you will have to from the dynamic SQL statement using sprintf. Depending upon your condition you can from the SQL statement as follows

if ( condition == TRUE)
{
 sprintf (szDynamicSQl ,"SELECT * FROM TLITEMCODE WHERE CHECK = TRUE" );
}
else
{
 sprintf (szDynamicSQl ,"SELECT * FROM TLITEMCODE WHERE CHECK = FALSE" );
}

By using direct TRUE or FALSE in the SQL statement, SQL server will take appropriate value for it. Generaly TRUE is any non zero value and FALSE is always ZERO.
 
You can open the database and can check, what values are being stored in database for TRUE and FALSE.

I hope this will clear your doubt.



0
 

Author Comment

by:dekoay
ID: 1178930
Hello pagladasu,

I know what u r saying but the problem is what is the logic value I should put to replace the TRU/FALSE value. In SQL server, data is record as -1(True) and 0(False). I did follow it but unfortunately, it didn't give me a right record. As u can see from below :

strcpy(statement, "SELECT * FROM tblItemCode WHERE Check = -1) // for true value
LPCSTR strSQL = statement
if SQL_SUCCESS == (rc = ::SQLPrepare(...etc)
  if SQL_SUCCESS == (rc = :SQLExecute(...etc)
    if (rc == SQL_SUCCESS)
      SQLBindCol(hstmt, 2,  <what data type should use here>, &value, 0, &cb)
   }
}
}

I didn't get the right value for this particular field...Yur help will be much appreciate. TQ
Derrick

   
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1178931
Did you try SQL_INT? If it hasn't worked, you may try SQL_TINYINT.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question