Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now