Guest User

Guest User

  • Tech Writer
  • 4
  • 808

C# Nested IF Statements

Dec 6 2022 3:16 PM
//Help converting these sql statements to C# (Also, sorry for the formatting)

// #1
DECLARE NUM_OF_ITEMS CHARACTER;

IF NUM_OF_ITEMS IS NOT NULL THEN      
    IF NUM_OF_ITEMS > 100 THEN
       SET NUM_OF_ITEMS = '100';
    END IF;    
END IF;  

 
//This is what I have so far... 

public string (string numOfItems) 
{
   if (numOfItems!= null)
   {
     if (numOfItems > 100)
     {
         numOfItems == "100";
      }
    }
}

// #2...........

DECLARE ID CHARACTER;
DECLARE result CHARACTER

IF ((ID IS NOT NULL) AND (ID <> '')) THEN

    DECLARE TEMP_ID INTEGER;  

    SET TEMP_ID = CAST(ID AS INTEGER);

     IF ((TEMP_ID >= 1) AND (TEMP_ID < 25) AND (LENGTH(ID) < 5)) THEN
         SET result = result || ID;


    
// This is what I have so far but not sure if im going in the correct direction... 
                 
public string(string ID){
StringBuilder result = new StringBuilder();
if (!string.IsNullOrEmpty(ID))
{
   int TEMP_ID = Int32.TryParse(ID, out TEMP_ID);
        if ((TEMP_ID >= 1) && (TEMP_ID < 25) && (ID.Length < 5))

        {
            result.Append(ID);

        }
}

 

 


Answers (1)