[Solved] Using sql statement inside if condition [closed]


If its a c# code then you can use contains to check the stageID

if(stageID.Contains(1))
{
//your code
}
else if(stageID.Contains(2))
{
//your code
}
else
{
// your code
}

if its a SQL code

DECLARE 
   stageID number(3) := 100; 
BEGIN 
   -- check the boolean condition using if statement  
   IF( stageID < 20 ) THEN 
      -- if condition is true then print the following   
      dbms_output.put_line('stageID is less than 20 ' ); 
   ELSE 
      dbms_output.put_line('stageID is not less than 20 ' ); 
   END IF; 
   dbms_output.put_line('value of stageID is : ' || stageID); 
END; 

to get data in stageID from sql in c#

try{
    int stageID  = 0;
    string strConnect = @"Database=Database_Name;Data Source=Your_Server_Name;Initial Catalog=Your_Db_Name;Integrated Security=True";
    using (SqlConnection con = new SqlConnection(strConnect))
    {
        con.Open();
        con.InfoMessage += new SqlInfoMessageEventHandler(con_InfoMessage);
    }
    SqlConnection Conn = new SqlConnection(Connection_String);
    SqlCommand Comm1 = new SqlCommand(Command, Conn);
    Conn.Open();
    SqlDataReader DR1 = Comm1.ExecuteReader();
    if (DR1.Read())
    {
        stageID   = Convert.ToInt32(DR1.GetValue(0));
    }
    Conn.Close();
}
catch(exception ex)
{
// your exceptio code
}

do let me know for more help

9

solved Using sql statement inside if condition [closed]