SQL Execute

Results 1 to 5 of 5
  1. #1
    Member idohadar is offline
    MemberRank
    Jun 2010 Join Date
    52Posts

    SQL Execute

    I'm makign a program, for create account, edit and more ..
    I started with create acouunt.
    and i wanna check when i create account.
    If the account already exist. and he is i'll send message or someing ..

    I check in SQL Server 2005 this execute:
    PHP Code:
    if exists (select 'idohadar' from [Accountwhere [UserID] = 'idohadar')
    begin
        select 
    'Ido' from [Accountwhere [Name] = 'Ido'
    end 
    Just way to check if this account exist ..
    In my C++ Program i used in this func to execute (ODBC):
    PHP Code:
    sprintf(String"if exists (select 'idohadar' from [Account] where [UserID] = 'idohadar')");
    strcpy((char*)SqlQueryString);
    RetCode SQLExecDirect(hStmtSqlQuerySQL_NTS);
    if(
    RetCode)
    {
        
    MsgBox("Exist");
    }
    else
    {
        
    MsgBox("Not Exist");

    But I don't know what the 'RetCode' should return if its exist or not, i tried the all returns .. (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO and the others ..)
    Any idea :D ?


  2. #2
    Valued Member SandOfTime is offline
    MemberRank
    Mar 2011 Join Date
    112Posts

    Re: SQL Execute

    sprintf(String, "if exists (select * from [Account] where [UserID] = 'idohadar')");

    try it

  3. #3
    Member idohadar is offline
    MemberRank
    Jun 2010 Join Date
    52Posts

    Re: SQL Execute

    Quote Originally Posted by SandOfTime View Post
    sprintf(String, "if exists (select * from [Account] where [UserID] = 'idohadar')");

    try it
    NO, still not working ..

  4. #4
    Hi, I'm Omar! Vusion is offline
    MemberRank
    Jan 2011 Join Date
    HereLocation
    1,658Posts

    Re: SQL Execute

    That query wouldn't do at all.
    Try something like this first of all.
    Code:
    SELET UserID FROM Account WHERE UserID = 'idohadar'
    And afaik, there should be a function that contains the number of rows returned from such select statement. So, all you gotta do is to use this function to check if the query returned more than 0 rows, if so, msgbox userid exists.

  5. #5
    Member idohadar is offline
    MemberRank
    Jun 2010 Join Date
    52Posts

    Re: SQL Execute

    Quote Originally Posted by Vusion View Post
    That query wouldn't do at all.
    Try something like this first of all.
    Code:
    SELET UserID FROM Account WHERE UserID = 'idohadar'
    And afaik, there should be a function that contains the number of rows returned from such select statement. So, all you gotta do is to use this function to check if the query returned more than 0 rows, if so, msgbox userid exists.
    Thanks man :)
    You really helpful ^^



Advertisement