Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object modeling - load and save functions 5 62
Which IDE to use to begin C++ training? 5 66
Getting IP address 8 89
How do I get Window Title of all opened process? 4 15
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

830 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