Solved

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

Posted on 1998-11-30
4
169 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
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

777 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