user input , user inputs data into the list - input

I have a eval solution , that the user need to input the names of the people and give a certain value , i am trying to make it work but the input part is not working.
preferencia(ana,joana,1).
preferencia(ana,rui,-1).
preferencia(ana,maria,1).
preferencia(ana,jose,-1).
preferencia(ana,tiago,-1).
preferencia(ana,andre,1).
preferencia(joana,rui,2).
preferencia(joana,maria,1.5).
preferencia(joana,jose,-1).
preferencia(joana,tiago,1).
preferencia(joana,andre,-1).
preferencia(rui,maria,1).
preferencia(rui,jose,-1).
preferencia(rui,tiago,1).
preferencia(rui,andre,1).
preferencia(maria,jose,-1).
preferencia(maria,tiago,1).
preferencia(maria,andre,-1).
preferencia(jose,tiago,1).
preferencia(jose,andre,1).
preferencia(tiago,andre,-1).
preferencia(X,Y,D):-preferencia(Y,X,D),!. % reverse preferenciaance
% representation: S is a list of persons
% evaluation function:
eval([_],0).
eval([Name1,Name2|R],DS):-
preferencia(Name1,Name2,D),
eval([Name2|R],DR),
DS is D+DR.
start :- write('Pick 2 Person to make a group '), read(X), eval([X,X|R],DS).
i want the user to input 2 names via console , so i want is the console working like this , "Pick 2 Person to make a group" the user inputs the (ex. rui , maria) , and return the value of their preference. If i input eval([rui,mariaR],DS) it returns the value 1 , but this in only in static way , i want the user being able to select 2 names and return their preference level. I believe the main error is the start function , thanks

Related

Asterisk in variable not considered like % in SQL

I created these three radio buttons to define values to the variable TEST.
The first two work just fine: if I click in p_r1 it assigns B and if I click p_r2 it assigns A.
I wanted the third to assign * to get all status i.e A, B, C.
Why doesn't it work? Isn't * a special character that means all like % in SQL?
DATA: TEST TYPE C.
PARAMETERS:
P_R1 RADIOBUTTON GROUP GRP1 DEFAULT 'X',
P_R2 RADIOBUTTON GROUP GRP1,
P_R3 RADIOBUTTON GROUP GRP1.
IF P_R1 = 'X'.
TEST = 'B'.
ELSEIF P_R2 = 'X'.
TEST = 'A'.
ELSEIF P_R3 = 'X'.
TEST = '*'.
ENDIF.
SELECT VBELN,GBSTK
FROM LIKP
WHERE GBSTK = #TEST
INTO TABLE #DATA(IT_FINAL).
CL_DEMO_OUTPUT=>DISPLAY( IT_FINAL ).
A few things to keep in mind to make your requirement work:
An = or EQ in the where condition does not allow for wildcards. I.e. when test equals '*' in your example it will only find entries in the database table where GBSTK equals '*', most probably zero entries
To use wildcards you need to use LIKE instead of = or EQ
The general wild card to mach any string is '%' and not '*'
For more details check the SAP help for SELECT - WHERE for your specific version. Here is the one for 752: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapwhere.htm?file=abapwhere.htm

Generate 100 data randomly, or select if it is possible

I want to test my model , I need to test it in some data , I want to generate data , in fact I want to have 125 different parameter from 0 to 10000.
For example , in below we have 4 different parameter ,from 1 to 300.
Set I/0*300/;
Parameter MyParameter;
MyParameter /4 1,10 1,42 1,87 1/;
I don't want to do this by hand.
Is there any method that I generate it automaticly.
another way asking:
how can Select 4 random element of a set ' I' , without repetition?
Try this:
Set I /0*300/
picks /p1*p4/;
Scalar pick;
Parameter MyParameter(I);
MyParameter(I) = 0;
loop(picks,
pick = uniformInt(1, card(I));
* Make sure to not pick the same one twice
while(sum(I$(pick=ord(I)),MyParameter(I))=1,
pick = uniformInt(1, card(I))
Display 'here';
);
MyParameter(I)$(pick=ord(I))=1;
);
Display MyParameter;

SQL - When a column has a value from a list and a value not in that same list

Not sure the best way to word this but I'm looking for a way to specify a condition when a value in a column has at least one value in a given list AND avalue not in the same list, then that column's value should show up. An example table:
email program
john#john.com program1
john#john.com program2
john#john.com program3
jeff#jeff.com program3
jeff#jeff.com program4
steve#steve.com program1
steve#steve.com program2
If I have this table and a list of (program1, program2), I would like the corresponding email to show up if the programs associated with a given email match at least one in the given list AND if the given email has a program NOT in the given list
So for the table above and the given list above all we would have show up with the correct query would be:
email
john#john.com
Any help on this would be greatly appreciated. Note: this would be in Redshift/PostgreSQL
I like doing this with group by and having. Here is a pretty general approach:
select email
from t
group by email
having sum( (program = 'program1')::int ) > 0 and
sum( (program = 'program2')::int ) = 0;
In this case, "program1" is required and "program2" is not. And, you can keep adding conditions -- as many as you like.
I forget if Redshift supports the :: syntax. You can always express this using standard SQL:
having sum( case when program = 'program1' then 1 else 0 end ) > 0 and
sum( case when program = 'program2' then 1 else 0 end ) = 0;
EDIT:
I think #dnswit is right on the parsing of the OP's question. The logic would be:
having sum( (program in ('program1', 'program2'))::int ) > 0 and
sum( (program not in ('program1', 'program2'))::int ) > 0;
if you just want a single list of emails no matter how many times they are on the list by having multiple programs
it is just select distinct email from tablename
First your Data Table is constructed wrong, you should use an unique Identifier so you can retrieve the program version you are specifying.
so your database should look like this:
> email program1 program2 program3
john#john.com ProgVersion1 ProgVersion2 ProgVersion3
steve#steve.com ProgVersion1 ProgVersion2 ProgVersion3
If you notice of the table above you can now query to get the program value you need for the specified Email. Use SQL Query, your Data Fields for your table are email, Program 1 Program 2 Program 3, when retrieving the value of the fields to be displayed, you are using redundancy you do not need to repeat the email address multiple times for each version of the program. This would not be expectable methodology.
SQL Query you can use:
instructions: you will create a parameter to use as a variable to query the data table from the list.
> CREATE PROCEDURE spLoadMyProgramVersion
>
> #email nvarchar(50),
>
> AS
>
>BEGIN
>SELECT program1,program2,program3
>FROM MyTableName
>WHERE (email LIKE #email) RETURN
This will allow you to load all your program version in a list by just specify the email address you want to load, this is a loading stored procedure just use it when you make a SQLCommand Object you can call your stored procedure.

APEX 5: How can I store the results of a MultiSelection from a List in an APEX-Item?

My example list:
How can I store the results in the Input Field "Your Choose" as comma-separate values (in this example: ALABAMA, ARIZONA).
Would APEX_UTIL.TABLE_TO_STRING be suitable?
You need to be more specific while asking questions.
I assume that you have page with
item PX_MULTISELECT.
process Before Header that loads data from DB to the input PX_MULTISELECT
And basing on this I assume you are asking how to get data separated with : from DB.
In process that loads data you should fetch data from db using listagg function
begin
select
listagg(COLUMN, ':') within group (order by 1)
into
:PX_MULTISELECT
from
...
where
...
end;
LISTAGG documentation

using multiple parameters in append query in Access 2010

I have been trying to get an append query to work but I keep getting an error stating that 0 rows are being appended whenever I use more than 1 parameter in the query. This is for a
The table in question has 1 PK which is a GUID [which is generating values with newid()] and one required field (Historical) which I am explictly defining in the query.
INSERT INTO dbo_sales_quotas ( salesrep_id
, [year]
, territory_id
, sales_quota
, profit_quota
, product_super_group_uid
, product_super_group_desc
, class_9
, Historical
, sales_quotas_UID )
SELECT dbo_sales_quotas.salesrep_id
, dbo_sales_quotas.Year
, dbo_sales_quotas.territory_id
, dbo_sales_quotas.sales_quota
, dbo_sales_quotas.profit_quota
, dbo_sales_quotas.product_super_group_uid
, dbo_sales_quotas.product_super_group_desc
, dbo_sales_quotas.class_9
, dbo_sales_quotas.Historical
, dbo_sales_quotas.sales_quotas_UID
FROM dbo_sales_quotas
WHERE (((dbo_sales_quotas.salesrep_id)=[cboSalesRepID])
AND ((dbo_sales_quotas.Year)=[txtYear])
AND ((dbo_sales_quotas.territory_id)=[txtTerritoryID])
AND ((dbo_sales_quotas.sales_quota)=[txtSalesQuota])
AND ((dbo_sales_quotas.profit_quota)=[txtProfitQuota])
AND ((dbo_sales_quotas.product_super_group_uid)=[cboProdSuperGroup])
AND ((dbo_sales_quotas.product_super_group_desc)=[txtProductSuperGroupDesc])
AND ((dbo_sales_quotas.class_9)=[cboClass9])
AND ((dbo_sales_quotas.Historical)='No')
AND ((dbo_sales_quotas.sales_quotas_UID)='newid()'));
Even if I assign specific values, I still get a 0 rows error except when I reduce the number of parameters to 1 (which it then works perfectly regardless of which parameter) I have verified that the parameters have the correct formats.
Can anyone tell me what I'm doing wrong?
Break out the SELECT part of your query and examine it separately. I'll suggest a simplified version which may be easier to study ...
SELECT
dsq.salesrep_id,
dsq.Year,
dsq.territory_id,
dsq.sales_quota,
dsq.profit_quota,
dsq.product_super_group_uid,
dsq.product_super_group_desc,
dsq.class_9,
dsq.Historical,
dsq.sales_quotas_UID
FROM dbo_sales_quotas AS dsq
WHERE
dsq.salesrep_id=[cboSalesRepID]
AND dsq.Year=[txtYear]
AND dsq.territory_id=[txtTerritoryID]
AND dsq.sales_quota=[txtSalesQuota]
AND dsq.profit_quota=[txtProfitQuota]
AND dsq.product_super_group_uid=[cboProdSuperGroup]
AND dsq.product_super_group_desc=[txtProductSuperGroupDesc]
AND dsq.class_9=[cboClass9]
AND dsq.Historical='No'
AND dsq.sales_quotas_UID='newid()';
I wonder about the last 2 conditions in the WHERE clause. Is the Historical field type bit instead of text? Does the string 'newid()' match sales_quotas_UID in any rows in the table?