#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Colorado
    Posts
    4
    Rep Power
    0

    Question Need help comparing db field values in c++


    Hello,

    I am trying to compare 2 different text fields from ms sql db, and want to set a condition based on wether or not the 2 text fields contain the same text or not. I believe that c++ is setup to use a character array to hold the db fields, and I have tried to use strcmp to compare the values, but it seems like I am only getting comparisions on whether or not the db fields are NULL or not, and that it is not actually comparing the db field values.

    Basically all I need to do is:
    if field1 value is not equal to field2 value, then outofrange=1.

    I used != to specify inequality, but like I said before, it's almost like it's not looking at the value of the fields, only at whether or not the fields are NULL.

    Am I doing something wrong?

    I am pretty new to c++, apologies for my ignorence.

    Thanks in advance for any help!

    M
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    No es importante
    Posts
    2,065
    Rep Power
    14
    What happens when you capture the field values in variables and compare them at the variable level?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Colorado
    Posts
    4
    Rep Power
    0
    Hi Victor,

    Thanks for thr reply.
    I have compared at the variable level as well, but received the exact same results.

    M
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    No es importante
    Posts
    2,065
    Rep Power
    14
    Have you tried issue the comparison at the database level?
    Select if(col1 = col2, x, y) as result
    ...
    What datatype are the variables you compared?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Colorado
    Posts
    4
    Rep Power
    0
    sql datatype is varchar.

    I can not do compare at DB level because I am building upon existing code that performs other db field functions at C level already.

    M
  10. #6
  11. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    show us the code you used to compare the values
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Colorado
    Posts
    4
    Rep Power
    0
    Here is the code specific to the compare:


    if(outofrange) continue;
    outofrange=0;
    for(i=0;i<numsc;i++) {
    if (strcmp(sc[i].birace1, fam.accept_birace1)) outofrange=1;
    }

    Thanks,

    M

IMN logo majestic logo threadwatch logo seochat tools logo