C#
//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 = 1) && (TEMP_ID < 25) && (ID.Length < 5))
{
result.Append(ID);
}
}
Aravind GovindarajRank #430 · 5.8K reputationPosted Dec 6, 2022, 11:39 AM EST
Hi Chris, yes you are going in the right direction, however, needs a bit of tuning, please find a snippet for the same
private string (string numberOfItems)
{
return numOfItems != null && numOfItems >0 ? "100": string.Empty;
}
private string secondMethod(string id)
{
string result = string.Empty;
int tempId;
if (
!string.isnullOrEmpty(id)
&& id.length < 5
&& int.TryParse(id, out tempId)
&& tempId >= 1 && tempId < 25
&&
)
{
result = id;
}
return result;
}