This guide shows common SQL differences between MSSQL and Hana and provide guidelines to ease the migration of a software to hana.
It can help you using SAP Business One database/schema on Hana, and may also help you if you create your own schema like Nware does.
This is a list of common tricks to help you migrate. It is not complete as some sql queries are not common and need specific correction.
You can find SQL Documentation for the hana database here
http://help.sap.com/hana/html/index.html
http://help.sap.com/hana/hana_sql_ref_en.pdf
This guide assume that you already know how to connect to the database using the odbc driver, or the java driver. See my howto document for an example of connectionstring for the odbc driver. http://scn.sap.com/docs/DOC-33628
Common :
When dealing with fields name that are sql reserved word like "Group","Order", or fields with unicode characters in them like "Français", or fields that are case sensitive, use double quotes when accessing them.
Reason :
Microsoft SQL Support Square Braquets [] between fields, but hana does not support this.
Double quotes are supported by both database and is an ansi standart.
Example : Do Select Captions."Français" from Captions
Don't SELECT Captions.[Français] FROM Captions
To change a field type, use the CAST command
Reason : Convert does not exists on Hana.
Example : Do select Cast(Oitm."ItemCode" as varchar) as ItemCode from SBODEMOUS.OITM
Don't select Convert(varchar, Oitm."ItemCode") as ItemCode from OITM
Don't use MSSQL specific code when a standart sql syntax can be used. Standart sql syntax is more likely to work on hana than mssql sql syntax.
Reference : http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt and the hana reference guide above.
Reason : Using standart sql queries will ease the migration process and will reduce code rewrite
Example : DO SELECT OITM."ItemCode" As CustomName FROM OITM
Don't SELECT CustomName = OITM."ItemCode" FROM OITM
SAP Business One:
Use Quotes around fields in all your sql operations accessing SAP Databases.
Reason :
All sap fields are Case-sensitive. Table are Case Insensitive. Schema are Case Insensitive.
All queries in SAP Business One database need to have double quotes around all fiels and all fields need to be written
in the exact same case as they are in hana. If you don't have access to Hana to see the case sensitivity of the fields, for example in a SAP Business One database, use the same case as the field in MSSQL for a similar database. Microsoft will still work if you use the wrong case, hana will not.
Examples : Do select RDR1."Price" * RDR1."Quantity" as RawTotal from RDR1 where RDR1."DocEntry" = 1
Don't do select "PRICE", "price", price,"prICE" from RDR1
Data type :
Datetime :
If you want to save the current date and time in the database, use current_timestamp.
Reason : GetDate() does not exists in Hana. current_timestamp is supported by both database and is an ansi standart.
Examples : DO Update LisaTransation Set SAPDateTime = current_timestamp where ...
Don't Update LisaTransation Set SAPDateTime = getdate() where ...
Varchar,nvarchar,text :
All text search operations are case sensitive in hana. "Motherboard" is different from "MOTHERboarD".
If a particular field should not be case sensitive, you have to do all search in an case-insensitive manner using the UPPER sql command.
Reason : In MSSQL, the collation you use may be case insensitive. In Hana, there is no collation support, or only 1 collation and it is case sensitive.
Some examples fields where search should be done case insensitive. This list is is not complete :
OITM.ItemCode
OITW.WhsCode
Example : Do Select "ItemName" from OITM where UPPER("ItemCode") = UPPER('user input')
Don't Select "ItemName" from OITM where "ItemCode" = 'user input'
try to keep the same case sensitivity between all duplicated text keys in the database.
Reason : as previously noted, all search are case sensitive. If SAP.OITM.ItemCode is different in case-sensitive collation than othertable.ForeignKeyToItemCode, then any join will fail.
If you cannot keep the sensitivity, then you must use UPPER when comparing both fields in join.
Default ordering of text value may be different in MSSQL and Hana.
Reason : This is because of case sensitivity. For complete detail, please read NOTE 1760104 - SQL statement results are ordered differently in MS SQL Server and SAP HANA
Program :
When dealing with boolean flags (usually configurable settings) in an application, implicitely convert the database value to Boolean when using in a if.
Reason : In MSSQL, the field type is bit and is automatically converted to true/false. In Hana, the bit field does not exists and you can use the tinyint data type that contains integer between 0 and 255. Interger value 0 or 1 are not automatically converted to true/false and the programmer need to convert that value to boolean.
Example : Do c# If ( Convert.ToBoolean( rsSQL( "ManBtchNum" ) )) {
Don't If ( rsSQL( "ManBtchNum") ){
Common Problem not yet resolved :
Some of these problems will require IF Hana then do this sql in the code.
sql "IF" : They don't work as standart SQL In hana. It only work in SQLScript function. We use them most of the time to check if a table/column exists, and create it if not. This method don't work on hana yet. If you can do this in a separate function, migration will be easier. In Hana Sys.Tables and SYS.view_columns provide the field existance functionnality, but you cannot do if Hana exists then create table.
Example :
Do : C# if ( CheckIfColumnExistsFunction ("Table","Column") {
strSQL = "Alter Table ..."
}
Don't : strsql = "IF syscolumns.. .. then alter table ... "
DateTime operations : there is no cross compatible way to do datetime operation on both database.
MSSQL : you can cast to a decimal, which return the number of days with decimals between the date and 1900-01-01, DateAdd, DateDiff,DatePart
Hana : Cannot cast to decimal, Add_days, Days_between, specific function for extracting date part.
Text concatenation : there is no cross compatible way to do text concatenation on both database