Split 8s

Follow the golden rule and always split eights and aces no matter what the dealer upcard happens to be. Splitting aces will result in significant gains for the player. Splitting 8's for the most part is a defensive play that will cut down on your losses. But keep in mind you will lose your fair share of hands when you split 8's, but if you were. Whenever you split a pair of eights each eight receives a new card and becomes a separate hand. You can then act on that hand according to the rules of blackjack by hitting, standing, or doubling down. You can even split the eights a second or third time. This is how aces and eights are handled at the blackjack table according to basic strategy. A split pair of eights is expected to win against dealer upcards of 2 through 7 and to lose less against dealer upcards of 8 through ace. If a player hits on a pair of eights, he is expected to lose $52 for a $100 bet. If the player splits the eights, he is expected to lose only $43 for a $100 bet. Split Eights is closed for the winter. We look forward to seeing you when we reopen! In the meantime, stay safe, friends & neighbors! Thank you for your support.

Always Split 8s

Introduction

In this post I would like to describe options for splitting concatenated string into multiple rows using SQL in SAP HANA. Depending on which version of HANA system you are working you can choose the one which is valid.

Creating custom function (when SAP HANA system version is 2.0 SP02 or lower)

If your HANA system is of version 2.0 SP2 or older, then there is no in-built function for splitting strings, that’s why you will need to create custom function.

Scenario 1.

You have the comma separated string ‘A1,A2,A3,A4,A5,A6’ which you want to display as multiple rows. Below there is a code for table function splitting comma separated string into multiple lines.

Split

*If your string is separated by different delimiter simply replace ',' with other symbol.

Now let’s query the function for the string which we need to split:

Result:

Using SQLSCRIPT built-in Library (recommended when SAP HANA version is 2.0 SP03 or higher)

Version 2.0 SP03 of SAP HANA offers new enhancement of SQLScript library – SQLSCRIPT_STRING. Functions within this library enables easy way of splitting string into multiple rows. Additionally developer has more flexibility to define splitting rules.

Scenario 1

You have the comma separated string

which you want to display as multiple rows.

Use following code:

I. Explicitly declare usage of SQLSCRIPT_STRING library. Assign alias for the library (in this example name of the alias is “LIBRARY”, but you can assign any other name)

II.Explicitly declare output table

III.Use SPLIT_TO_TABLE function. Combine it with the alias assigned in point I. As input for SPLIT_TO_TABLE function use string which you want to split, and after comma define delimiter (in this example comma is delimiter). At the end you need to assign output of that function to the table variable defined in point II.

Split

IV. Query the table variable

Split Shot

After running following the query string will be splitted into multiple rows:

Result:

Scenario 2

There is a string which combines first and last name, phone and the address:

You want to split this string into three values: full name, phone, address.

Use following code:

Result:

Here I used third optional parameter (MAXSPLIT) which is available for SPLIT_TO_TABLE and assigned value of 2. This way I will limit the split to only first two comma occurrences (subsequent commas will not be considered).

Besides defining delimiter for split, you can also specify maximum number of splits. Function takes first n-number of delimiter occurences, and remaining part is being displayed in the last row. As you can see in the string from the example there are 4 commas, so if this parameter would not be specified, then in output there would be 5 rows.

Split 8s

Scenario 3

There is a string which combines number, date and time. It’s separated by #, DATE, TIME string:

You want to split this string into three strings: number, date, time.

Use following code:

Output:

Here I used function SPLIT_REGEXPR_TO_TABLE. It can be combined with regular expressions, which gives user even more options for defining logic for splitting strings. Regular expression from the example splits string after each occurencs of # symbol or uppercase alphabet string.

Summary

Split 8s Against 10

SAP HANA SPS 02 introduced built-in libraries giving SQL developers new functions. In SPS 03 new librarary SQLSCRIPT_STRING has been added which contains multiple functions for manipulating with strings. If you want to find out more about SQLSCRIPT_STRING library, check SQLScript reference by SAP.

If your system is running on older version of SAP HANA, as workaround you can develop custom function as described in the post.

In my next post you can check how to Split table column value into multiple rows using SQL in SAP HANA

Split

When To Split 8s

Thanks for reading!