- Posts: 109
SQL statement on an InMemory Table
- JD Cox
- Topic Author
- Offline
- User
Less
More
2 years 1 week ago #3680
by JD Cox
SQL statement on an InMemory Table - Post(3680) was created by JD Cox
Is it possible to execute a SQL statement on an InMemory Table inside a .NET Heater?
I don’t need to pass any parameters and I know I can get the results I’m looking for with a few IF heaters. Looking for a cleaner option.
JD
I don’t need to pass any parameters and I know I can get the results I’m looking for with a few IF heaters. Looking for a cleaner option.
JD
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
2 years 1 week ago - 2 years 1 week ago #3681
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic SQL statement on an InMemory Table - Post(3681)
Hi JD,
Yes, but only simple SQL selects allowed. For example, the below listed SQLs would be possible
object o = AdapterWrite.Execute("select [FieldName] from [TableName] where [id] = " + id.ToString(), true);
object o = AdapterWrite.Execute("select count(*) from [TableName] where [id] = " + id.ToString(), true);
Please find attached a simple example.
Yes, but only simple SQL selects allowed. For example, the below listed SQLs would be possible
object o = AdapterWrite.Execute("select [FieldName] from [TableName] where [id] = " + id.ToString(), true);
object o = AdapterWrite.Execute("select count(*) from [TableName] where [id] = " + id.ToString(), true);
Please find attached a simple example.
Best wishes
Robert Stark
Last edit: 2 years 1 week ago by FlowHeater-Team.
Please Log in or Create an account to join the conversation.
- JD Cox
- Topic Author
- Offline
- User
Less
More
- Posts: 109
2 years 6 days ago #3682
by JD Cox
Replied by JD Cox on topic SQL statement on an InMemory Table - Post(3682)
The InMemory table I need the value from is not on the Read or Write side.
This is what I'm trying to do, I'm getting an error on lines 11 and 16.
Please note that C# is not my thing.
public object DoWork()
{
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
int i = (int)InValues[0].GetInt();
switch (i)
{
//Pallet In
case 1:
return InMemoryAdapter.Execute("select PVAL from PRICING where PTYPE = 20", true);
break;
//Carton In
case 2:
return InMemoryAdapter.Execute("select PVAL from PRICING where PTYPE = 25", true);
break;
default:
{
//Others
return 100;
break;
}
}
}
Thanks, JD
This is what I'm trying to do, I'm getting an error on lines 11 and 16.
Please note that C# is not my thing.
public object DoWork()
{
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
int i = (int)InValues[0].GetInt();
switch (i)
{
//Pallet In
case 1:
return InMemoryAdapter.Execute("select PVAL from PRICING where PTYPE = 20", true);
break;
//Carton In
case 2:
return InMemoryAdapter.Execute("select PVAL from PRICING where PTYPE = 25", true);
break;
default:
{
//Others
return 100;
break;
}
}
}
Thanks, JD
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
2 years 6 days ago - 2 years 3 days ago #3683
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic SQL statement on an InMemory Table - Post(3683)
Hi JD,
you just have to create a InMemoryAdapter inside the script, see below.
It would also be posible to lookup the data via the String Replace Heater like this.
you just have to create a InMemoryAdapter inside the script, see below.
Code:
public object DoWork()
{
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
// Just create a InMemoryAdapter instance
InMemoryAdapter adapter = new InMemoryAdapter();
int i = (int)InValues[0].GetInt();
switch (i)
{
//Pallet In
case 1:
return adapter.Execute("select PVAL from PRICING where PTYPE = 20", true);
//Carton In
case 2:
return adapter.Execute("select PVAL from PRICING where PTYPE = 25", true);
//Others
default:
return 100;
}
}
It would also be posible to lookup the data via the String Replace Heater like this.
Best wishes
Robert Stark
Last edit: 2 years 3 days ago by FlowHeater-Team.
Please Log in or Create an account to join the conversation.
- JD Cox
- Topic Author
- Offline
- User
Less
More
- Posts: 109
2 years 6 days ago #3684
by JD Cox
Replied by JD Cox on topic SQL statement on an InMemory Table - Post(3684)
Perfect
Thanks Robert
As far as the Replace Heater thanks for the tip.
But, this is just the first step in the .NET Heater.
JD
Thanks Robert
As far as the Replace Heater thanks for the tip.
But, this is just the first step in the .NET Heater.
JD
Please Log in or Create an account to join the conversation.
- JD Cox
- Topic Author
- Offline
- User
Less
More
- Posts: 109
2 years 5 days ago - 2 years 5 days ago #3685
by JD Cox
Replied by JD Cox on topic SQL statement on an InMemory Table - Post(3685)
Thanks again Robert
Works great. Sharing this if it helps anyone else.
Here’s what I did to work out the math.
public object DoWork(){
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
// Create a InMemoryAdapter instance
InMemoryAdapter adapter1 = new InMemoryAdapter();
InMemoryAdapter adapter2 = new InMemoryAdapter();
int i = (int)InValues[0].GetInt(); //pallet = 1 carton = 2
int iremaining = 30-DateTime.Now.Day; //days remaining in month for initial pallet charge
decimal ival = 0;
switch (i)
{ //Pallet In
case 1:
//initial pallet month
object oipallet = adapter1.Execute("select PVAL from PRICING where PTYPE = 40", true);
//pallet in charge
object opalletin = adapter2.Execute("select PVAL from PRICING where PTYPE = 20", true);
return ival = ((Convert.ToDecimal(oipallet)*iremaining)/30)+Convert.ToDecimal(opalletin);
break;
//Carton In
case 2:
//carton in charge
return adapter2.Execute("select PVAL from PRICING where PTYPE = 25", true);
break;
default:
{ //Others
return 1000;
break; }
}
}
Image shows the difference it made.
JD
Works great. Sharing this if it helps anyone else.
Here’s what I did to work out the math.
public object DoWork(){
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
// Create a InMemoryAdapter instance
InMemoryAdapter adapter1 = new InMemoryAdapter();
InMemoryAdapter adapter2 = new InMemoryAdapter();
int i = (int)InValues[0].GetInt(); //pallet = 1 carton = 2
int iremaining = 30-DateTime.Now.Day; //days remaining in month for initial pallet charge
decimal ival = 0;
switch (i)
{ //Pallet In
case 1:
//initial pallet month
object oipallet = adapter1.Execute("select PVAL from PRICING where PTYPE = 40", true);
//pallet in charge
object opalletin = adapter2.Execute("select PVAL from PRICING where PTYPE = 20", true);
return ival = ((Convert.ToDecimal(oipallet)*iremaining)/30)+Convert.ToDecimal(opalletin);
break;
//Carton In
case 2:
//carton in charge
return adapter2.Execute("select PVAL from PRICING where PTYPE = 25", true);
break;
default:
{ //Others
return 1000;
break; }
}
}
Image shows the difference it made.
JD
Last edit: 2 years 5 days ago by JD Cox.
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
2 years 3 days ago #3686
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic SQL statement on an InMemory Table - Post(3686)
Hi JD,
Thanks for the information. This be helpful for some others, great.
There was an error after migration the Forum software. Now it would be possible to add images. May I ask you to add your mentioned image, Thanks.
Thanks for the information. This be helpful for some others, great.
There was an error after migration the Forum software. Now it would be possible to add images. May I ask you to add your mentioned image, Thanks.
Best wishes
Robert Stark
Please Log in or Create an account to join the conversation.
- JD Cox
- Topic Author
- Offline
- User
Less
More
- Posts: 109
2 years 3 days ago #3687
by JD Cox
Replied by JD Cox on topic SQL statement on an InMemory Table - Post(3687)
You got it, thanks again.
Attachments:
Please Log in or Create an account to join the conversation.
Time to create page: 0.303 seconds