//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);
}
}
Loading
Aravind GovindarajPosted Dec 6, 2022, 4:39 PM
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;
}