I am using toad and wrote a query which is executed without any error message
but data is not updated.
could you please please find what is wrong here?
MERGE INTO aa USING DUAL ON (a = :a)
WHEN MATCHED THEN
UPDATE
SET b = CASE
WHEN NAME= 'b' THEN :b
WHEN NAME= 'c' THEN :c
END
WHEN NOT MATCHED THEN
INSERT (d,e, f, g, h ) VALUES (700000, :a, :e, 'z', 'y');
Thanks in advance!
Related
Hi I'm working on a snowflake query.
Case when x = a then 1
When ifnull(a,' ') <> b then 1 end as
I'm hiding the original column names.
The above case statement throwing error
invalid argument types for function '<>':(Row(varchar(25),varchar(1)),varchar(11)) .
Please help me!
i tried this and it worked, please check your code.
create or replace table test(x varchar2, a varchar2, b varchar2) ;
select a, b, case when x = a then 1
when ifnull(a, '') <> b then 1 end from test;
I want to set a formula for a field C by check two picklist fields A and B (the value in the picklist will Yes, No, None)
If field A = "Yes" and field B = "Yes" then field C = "1"
If field A = "Yes" and field B <> "Yes" then field C = "2"
If field A <> "Yes" and field B = "Yes" then field C = "3"
If field A <> "Yes" and field B <> "Yes" then field C = "4"
I don't know how to set a formula for field C to make it works, I try CASE, IF statement without any luck.
Any help will be appreciated.
Thanks,
I would suggest to spend some times on these trailhead: Use Formula Fields and Advanced Formulas.
Bookmarking Formula Operators and Functions documentation page would be useful too.
Since A and B are picklist fields you must use ISPICKVAL(field, value).
If C is a text formula field:
IF( ISPICKVAL(A, 'Yes'),
IF ( ISPICKVAL(B, 'Yes'),
'1',
'2'
),
IF ( ISPICKVAL(B, 'Yes'),
'3',
'4'
)
)
I have a list of variables name "comorbid_names". And I want to select people who have those comorbidities in "comorbidities". However, I want to select the variable names if they are true.
For example patient 1 has "chd" only, therefore only that will be displayed as TRUE
comorbid_names
[1] "chd" "heart_failure" "stroke"
[4] "hypertension" "diabetes" "copd"
[7] "epilepsy" "hypothyroidism" "cancer"
[10] "asthma" "ckd_stage3" "ckd_stage4"
[13] "ckd_stage5" "atrial_fibrilation" "learning_disability"
[16] "peripheral_arterial_disease" "osteoporosis"
class(comorbid_names)
[1] "character"
comorbidities <- names(p[, comorbid_names][p[, comorbid_names] == 1])
At this point I get this error
Error: Unsupported use of matrix or array for column indexing
I am not entirely sure why, but I think it's to do with comorbid_names being character
Does anyone have an advice?
If p is a tibble as opposed to or in addition to a data.frame, you might be dealing with the following:
https://blog.rstudio.org/2016/03/24/tibble-1-0-0/
Look at the bottom of the post:
Interacting with legacy code
A handful of functions are don’t work with tibbles because they expect df[, 1] to return a vector, not a data frame. If you encounter one of these functions, use as.data.frame() to turn a tibble back to a data frame:
class(as.data.frame(tbl_df(iris)))
You might get along by doing p <- as.data.frame(p) as well.
Simply using p[, comorbid_names] == 1 will gave you the table of TRUE/FALSE values for your selected morbidities. To add the patient names or IDs to that list, use cbind, like this: cbind(p["patient_id"], p[, comorbid_names] == 1) where "patient_id" is the name of the column that identifies patients.
Here's a complete reproducible example:
comorbid_names <- c("chd", "heart_failure","stroke", "hypertension",
"diabetes", "copd", "epilepsy", "hypothyroidism",
"cancer", "asthma", "ckd_stage3", "ckd_stage4",
"ckd_stage5", "atrial_fibrilation", "learning_disability",
"peripheral_arterial_disease", "osteoporosis")
all_morbidities <- c("chd", "heart_failure","stroke", "hypertension",
"diabetes", "copd", "epilepsy", "hypothyroidism",
"cancer", "asthma", "ckd_stage3", "ckd_stage4",
"ckd_stage5", "atrial_fibrilation", "learning_disability",
"peripheral_arterial_disease", "osteoporosis",
"hairyitis", "jellyitis", "transparency")
# Create dummy data frame "p" with patient ids and whether or not they suffer from each condition
patients <- data.frame(patient_id = 1:20)
conditions <- matrix(sample(0:1, nrow(patients)*length(all_morbidities), replace=TRUE),
nrow(patients),
length(all_morbidities))
p <- cbind(patients, conditions)
names(p) <- c(names(patients), all_morbidities)
# Final step: get patient IDs and whether they suffer from specific morbidities
comorbidities <- cbind(p["patient_id"], p[, comorbid_names] == 1)
If you want to select only those patients that suffer from at least one of the morbidities, do this:
comorbidities[rowSums(comorbidities[-1]) != 0]
I am currently using the DBI module to connect to my MSSQL Database to pull some data from a table.
The row I am trying to pull contains a lot of text (it is of type ntext and can contain up to 6Mb of text).
My query is a very simple one at the moment:
my $sql = "SELECT TOP 1 [reportRow] from UsageReport";
And I also have LongTruncOk enabled for the Database options.
After I execute the query, I want to display the rows.
while ( my #row = $sth->fetchrow_array ) {
print "#row\n";
}
Unfortunately it displays the data in a very weird manner with spaces in between every character and it only retrieves the first 40 characters.
< r e p o r t > < r e p o r t h e a d e r > < m o n t h > O c t o b e r 2 0
If I use File::Slurp to output #row to a file, it displays as
Is there a reason the data is being cut off and is being displayed weird?
Edit: How would I convert UTF16 into a format that doesn't insert spaces between characters?
You need to set LongReadLen in addition to LongTruncOk. You've told DBI it's ok to cut off long results from the DB, and now you need to tell it how long of a string you're willing to accept.
In PyDatalog I have defined the following assertions:
#stations
assert_fact('station', 'A' ,'yellow')
assert_fact('station', 'B' ,'yellow')
assert_fact('station', 'C' ,'yellow')
assert_fact('station', 'D' ,'yellow')
#sections
assert_fact('stretch', 'A' ,'B')
assert_fact('stretch', 'B' ,'C')
assert_fact('stretch', 'C', 'D')
And I would like to ask the database if there is a way to get to D from A.
The following code should work, because it answers set([()]) if there is a way, and None if there isn't. But it doesn't give me the result of the different evaluations of Z. I would like to know also the route, for example: A B C D
load("""
route(X,Y) <= stretch(X,Y)
route(X,Y) <= stretch(X,Z) & route(Z,Y)
""")
I have tried with unbound values, but it only gives me the result of the first iteration:
load("""
route(X,Y,P) <= stretch(X,Y) & (P==Y)
route(X,Y,P) <= stretch(X,P) & route(P,Y,Z)
""")
I think that the problem is that it only takes P in the first iteration. Or should I use aggregation functions? I don't understand very well how I could use concat...
Thanks in advance.
You need a predicate with a variable that contains the nodes between the 2 end points. You could use the following definition of route():
load("""
route(X,P, Y) <= stretch(X,Y) & (P==[])
route(X,P, Y) <= stretch(X,Z) & route(Z,P1,Y) & ~(Z in P1) & (P==[Z]+P1)
""")
print(pyDatalog.ask("route('A', P, 'D')"))
# prints set([(('B', 'C'),)])
Lists are supported since pyDatalog 0.13.