Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-11-30
4
Medium Priority
?
174 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 100 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

730 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