I want to pass 'A0101', 'A0201' this like a parameter in sql server query using in clause but from c# to a sp
If the "IN" clause is just being used to filter, you can use Linq without passing it into the stored procedure (it will still be evaluated on server with deferred execution).
var results = (from item in context.SPCall
where new[] {"A0101", "A0201"}.Contains(item.Property)
select item).ToList();
Related
I'm using the #sap/hana-client npm module in a NodeJS project to connect to a HANA database and run queries.
I have a list of IDs that I want to include in a WHERE ID IN(...) SQL clause via parameterized queries, but cannot seem to figure out the syntax to do it.
Here's what I imagine it would look like (but this does not work, fails at the parameter binding stage)
const ids = [1,2,3,4];
const params = [ids];
const sql = "SELECT * FROM T WHERE ID IN (?)";
// this fails with => code: -20007, message: 'Can not bind parameter(0).', sqlState: 'HY000'
conn.query(sql, params, (err, result) => {
// process query results or errors
});
I know that in Postgres I can do this by using the UNNEST(...) 1 array function, but the same does not seem to work in HANA
That's a well-known difficulty with HANA.
ARRAY-like types are not natively supported in the client software.
Your (special) case of this, namely turning an array into a list of parameters for an IN clause requires some additional efforts.
See e.g. Errors with declared array/table variable values in SAP HanaDB SQL
The bottom line is that Postgres handles this special case specifically by replacing the single IN-clause parameter ? with a whole list of delimited values.
HANA does (sadly) not do something like that.
Instead, if you have to know in advance how many elements (at max) the IN-list will have so that you can prepare a statement with a parameter ? for each of those elements.
Alternatively, you can use SQLScript and the UNNEST construct that I've shown in the linked question, or you can create a temporary table, fill it with the IN-list elements and use it in the IN-clause (or join it).
Either way, it's rather cumbersome to manually do this, and I'd probably look for a framework that does that sort of stuff.
I am trying to allow the user to pass a text parameter in an SSRS report like this:
'value1','value2','value3','value4'
The idea is to use it in my dataset query in a where in clause.
I think SSRS passes the above parameter to the query like this:
"'value1','value2','value3','value4'" which messes up my query.
How can this work?
Yes you can definitely do that,
You need to create parameter as below
Then If you are using sql statement you can use in your sql statement as
select * from customer where customerid=#ReportParameter1
Here are 2 links for Ref
https://reportsyouneed.com/ssrs-tip-put-parameters-in-your-query-not-your-filter/
https://learn.microsoft.com/en-us/sql/reporting-services/tutorial-add-a-parameter-to-your-report-report-builder?view=sql-server-2017#Query
I have a simple sql query in orientdb function like this:
select *
from TestExecutionPlanReport
where executionPlan IN :executionPlans
It accepts "executionPlans" as parameter where an array value should be passed.
When I tried just one value like "#59:71", it works and return the wanted output. BUT when I tried to pass in an array value like "[#59:71,#59:214]", is not working. It returns an empty response. It works when I query "select * from SomeClass where field IN [#59:71,#59:214]" (Not in OrientDb function)
I had the same issue when trying to run an SQL query from Scala code. I solved it by passing a set as the parameter instead of a list or an array.
If I got your question right, you are trying to execute the query you've mentioned in a OrientDB server side function (probably written in JavaScript) which takes executionPlan as a parameter.
I also noticed this happening if you use parameterized queries. A parameterized query is something like the following;
var query = "select * from TestExecutionPlanReport where executionPlan IN ?";
return db.query(query, executionPlans);
However, when I used string concatenation to build the query, it works. I'm referring to the following
var query = "select * from TestExecutionPlanReport where executionPlan IN " + executionPlans
If you are using string concatenation I think the issue is with how you pass the parameter. Rather than passing "[#59:71,#59:214]", try passing [#59:71,#59:214] to your function and see if it works.
Usually when you use string concatenation to build queries, you can use the print() function to print the concatenated query on the OrientDB console. However, concatenation based queries could be exploited to do SQL injections, hence discouraged.
I cannot explain why this doesn't work for parameterized queries. I'll do more research on this. Perhaps it's a bug. I'm using OrientDB 2.0.3.
Hope this helps.
I want to use the "split" function in a simple query on my SSRS 2008 report. However, I get an error "Query execution failed for dataset "SlsmRealNum". "Split" is not a recognized built-in function name". But it's listed as a common function (text) if I open up the Expression box on the query, so not sure why it's failing?
my simple select statement is:
select slsm_num, slsm_msid from Salesman where slsm_msid = split(User.UserID,"\").GetValue(1)
right now to get the report to work, I have one parameter (SlsmnNum) that has the Split expression in it (to get the MSID of the user) and then a 2nd parameter that uses the above query in the Dataset Salesrepum using the #SlsmnNum parameter as the MSID. I'd like to not have to have 2 parapmeters if possible and just get the actualy salesrep # in just one. Any help is greatly appreciated!
Your select statement is executed as SQL so the error you are getting is actually from SQL server. This may be where you are getting confused.
There are two components to SSRS - SQL Statements and Report Expressions. Typically, SQL statements are used to generate datasets by querying the database. Report expressions are used to organize, aggregate, and filter the dataset once obtained from the SQL database. Since the SQL statement is executed IN the SQL database, only the functions that are in the database are available. The code you posted is a SQL statement not a Report Expression.
For example, you can't take a Report Expression and expect it to work in SSMS? No, because they are two different entities with wholly different syntax and purpose. When it comes to using built-in SSRS functions inside a SQL statement it will not work, the database has no concept of what the built in User.UserId is and as such you must use a parameter to transport the value over to the SQL query. This is definition and purpose of a parameter and why they exist.
Split is a function in SSRS which is why you see it in your expression reference, however, it is not a function in SQL. The code you posted is SQL syntax, so I am betting that this is the SQL statement that you are using to obtain your dataset. Therefore the query fails since the SQL DB does not have a Split Function.
You can add this split function to your database and the code is located here: Split String in SQL. You could also use something along the following in your where clause, the following is your updated SQL statement.
SELECT slsm_num, slsm_msid from Salesman where slsm_msid = SUBSTRING(#UserId, PATINDEX('%\%', #UserId), LEN(#UserId))
You would set the #UserId parameter's value to an expression of User!UserID rather than specifying it in your select statement.
The SSRS expression examples have a function similar to what your code is trying to accomplish if you were wanting the same thing in the report side. The function you are looking for is InStr(). On your report side you could use something along the lines of:
=Parameters!User.Value.Substring(Parameters!User.Value.IndexOf("\")+1, Parameters!User.Value.Length-Parameters!User.Value.IndexOf("\")-1)
Expression examples can be found here: MSDN Expression examples.
I am using EF to connect with Oracle database and writing a linq query like this
var keyword = this.Keywords.ToLower();
var filteredItems = from item in active_items
where item.Name.Contains(keyword)
select item;
The generated SQL from linq makes use of Like and keyword wrapped in %% signs.
e.g. WHERE "EXTENT1"."NAME" LIKE '%keyword%'
Which seems OK but I need the sql to make use "Contains" keyword and need the SQL to be like
e.g. WHERE CONTAINS(NAME,'keyword') > 0
How do I achieve this?
First option:
use devart library: http://blog.devart.com/using-oracle-full-text-search-in-entity-framework.html
Second option:
make a stored procedure in oracle that receive your keyword and search it and map the procedure into your model (if you are using model-first)
Third option:
in the linq mapping use a function like INSTR. See http://docs.oracle.com/cd/E11882_01/win.112/e18754/canonical_map.htm#ODPNT7777