H2 ALIAS for other built-in SQL functions - sql

Is it possible to use CREATE ALIAS in H2 not only for Java code, but also for other SQL functions?
For example, if I have a nested string manipulation
LOWER(SUBSTRING(REPLACE(REPLACE(...
it would be very handy to just create an alias, and use the created alias in the future instead of the whole set of nested functions.

Related

Using table valued params with Entity Framework

Is there a way to use SQL Server table-valued parameters in Entity Framework in a way that doesn't require you to use a stored procedure or string-based queries like context.Database.ExecuteSqlCommandAsync("") ?
Something similar to Dapper where I can pass a DataTable and specify the user-defined type name to use. Probably must be some sort of overload of IEnumerable<>.Contains() or .Join() so that I can build a join in a generated query.
The goal is to stay with expression trees and don't mess with strings.

How to use procedure call and non-standard SQL in Business Intelligence Publisher (BIP)

I have a function in my sql query. when I want to use it in BIP. I can use only standard SQL.
but I noticed there are two more options which are (procedure call) and (Non Standard SQL).
How to run my query. by using those two options.
the funtion (No info how to use it): CREATE OR REPLACE FUNCTION get_exchange_rate (....etc.)
The query (to run it in BIP):
NVL(SUM(ABS(DECODE(SIGN(ACCTD_AMOUNT_DUE_REMAINING*
get_exchange_rate('USD', :P_CURRTO, a.TRX_DATE) ),-1,
ACCTD_AMOUNT_DUE_REMAINING*
get_exchange_rate('USD', :P_CURRTO, a.TRX_DATE) ,0))),0) CREDIT_AMOUNT,

Access SQL SELECT Query: Required to use the table alias in WHERE clause?

Current Environment: Split Access Database, Local Access Front End, Access Backend on shared network drive
I'm writing a stupid long SELECT statement. Using table aliases to makes my code more readable.
I was taught to write out full table names in WHERE statements because they are executed before the FROM statement. However, when I did that - Access isn't finding the table / field referenced when I write the full table name out. Strangely, I tried using the alias in the WHERE statement and it works!!?
Does Access execute the statement differently than I was taught? Or am I unknowingly causing it to do it this way?
Shortened version of my SQL code that doesn't work:
SELECT [C].Multi_File_Case_ID,
[C].Case_Report_Number,
[C].Include_In_Casebook,
[C].Case_Status,
FROM Case_Tbl AS [C]
WHERE [Case_Tbl].Include_In_Casebook = True;
Edit: A word and a capitalization ;)
Once you define a table reference as an alias in the FROM, you need to use that alias everywhere in the query. The alias is more than a nickname; it is a name change for the scope of the query.
I would advise you to drop the square braces. Queries are easier to read and write as:
SELECT c.Multi_File_Case_ID, c.Case_Report_Number, c.Include_In_Casebook, c.Case_Status
FROM Case_Tbl AS c
WHERE c.Include_In_Casebook = True;
When you do not define a table alias, the table name itself serves as the alias.

What does the code following CREATE FUNCTION being a string imply?

From a great reply:
in PostgreSQL, CREATE FUNCTION is indeed a "SQL statement" but is is merely a
"wrapper" to specify a block of code that is executed by something
different than the SQL query "engine". Postgres (unlike other DBMS)
supports multiple "runtime engines" that can execute the block of code
that was passed to the "CREATE FUNCTION" statement - one artifact of
that is that the code is actually a string so CREATE FUNCTION only
sees a string, nothing else.
What are the consequences of "the code is actually a string so CREATE FUNCTION only sees a string, nothing else"?
Is that considered as dynamic SQL? Does it prevent or introduce SQL injection risk, compared to dynamic SQL?
How is that different from other RDBMS (if any?) where "the code is not a string"?
Thanks.
PostgreSQL is highly extensible, and you can for example define your own procedural language to write functions in.
PostgreSQL knows nothing about the language except that it has to call a certain language handler to execute the function.
The way that was chosen to implement this is to simplify pass the code as a string.
This is just an implementation detail and does not make PostgreSQL functions any more or less vulnerable to SQL injection than other RDBMS.
There are several levels on which you have to defend yourself against injection:
The function arguments: Here you should choose non-string data types whenever possible.
The SQL statements within the function: Here you should avoid dynamic SQL whenever possible, and if you have to use dynamic SQL, you should insert variables using the %L pattern of the format function.
Again, this is the same if function bodies are specified as strings or not.
All 3GL+ code is basically a string. The "parameter" passed to CREATE FUNCTION is code (to be executed outide the core SQL engine), which is a string (that's not SQL).
Other RDMS's only support SQL as the function/procedure body.

How do you port a SqlServer database to MySQL?

I have a SqlServer db that I would like to port to MySQL. What's the best way to to this. Things that need to be ported are:
Tables (and data)
FileStream → MySQL equivalent?
Stored Procedures
Functions
Data types are relatively similar.
There is no equivalent to FileStream in MySQL - the files must either be stored as BLOBs, or on the file system while the path is stored in the database.
Migrating away from TSQL means:
There's no WITH clause in MySQL - it will have to converted into a derived table/inline view
There's no TOP syntax - these have to be converted to use LIMIT
There's no ranking/analytic functionality in MySQL - can't use ROW_NUMBER, RANK, DENSE_RANK or NTILE. See this article for alternatives.
MySQL views have notoriously limited functionality:
The SELECT statement cannot contain a subquery in the FROM clause.
The SELECT statement cannot refer to system or user variables.
Within a stored program, the definition cannot refer to program parameters or local variables.
The SELECT statement cannot refer to prepared statement parameters.
Any table or view referred to in the definition must exist. However, after a view has been created, it is possible to drop a table or view that the definition refers to. In this case, use of the view results in an error. To check a view definition for problems of this kind, use the CHECK TABLE statement.
The definition cannot refer to a TEMPORARY table, and you cannot create a TEMPORARY view.
Any tables named in the view definition must exist at definition time.
You cannot associate a trigger with a view.
As of MySQL 5.0.52, aliases for column names in the SELECT statement are checked against the maximum column length of 64 characters (not the maximum alias length of 256 characters).
Dynamic SQL will have to be converted to use MySQL's Prepared Statement syntax
A guide/article with some useful tips is available on the official MySQL dev site.
This is not for the faint of heart. Here is an article that explains what you are in for:
http://searchenterpriselinux.techtarget.com/news/column/0,294698,sid39_gci1187176,00.html