Database Administrators
Q&A for database professionals who wish to improve their database skills
Latest Questions
1
votes
0
answers
20
views
Select groups of values that cover a date interval together
I have a database table with the following relevant columns: group_id, value, valid_from, valid_to None of those columns are unique (this is not the whole table). Data could look like this: | group_id | valid_from | valid_to | | -------- | ---------- | -------- | | 1 | 20250201 | 20250228 | | 2 | 20...
I have a database table with the following relevant columns:
group_id, value, valid_from, valid_to
None of those columns are unique (this is not the whole table).
Data could look like this:
| group_id | valid_from | valid_to |
| -------- | ---------- | -------- |
| 1 | 20250201 | 20250228 |
| 2 | 20250201 | 20250228 |
| 2 | 20250201 | 20250228 |
| 3 | 20250201 | 20250215 |
| 3 | 20250213 | 20250220 |
| 3 | 20250221 | 20250228 |
| 4 | 20250101 | 20250220 |
| 4 | 20250210 | 20250215 |
| 4 | 20250219 | 20250228 |
| 5 | 20250101 | 20250115 |
| 5 | 20250513 | 20250619 |
So each group has one or more entries. Every entry has a date interval. The intervals can overlap and are not unique.
Now I have the impossible task to determine all groups which cover a date interval together.
Let's say I need to find all groups that cover the interval 20250201 - 20250228.
With the test data shown, I would expect to find groups 1, 2, 3 and 4.
(None of the rows of group 3 cover the interval by themselves. But they overlap and cover the interval together).
I have to solve this with SQL ONLY but I can use multiple selects.
I'm a SAP Dev and I try to solve this with a HANA AMDP Method / SQLScript but feel free to give me any SQL solution you can come up with.
My idea was to select all of the date intervals that overlap (not cover it completely) with my needed date interval. Then use window function LAG() to select the previous date intervals of the group and check if they overlap, or if there is a gap.
If they overlap, I would take the
valid_from
of the previous row to widen/enhance the interval. This way I was hoping to create a entry that has the maximum covered interval of the group.
Then I could make one more select and look for entries that cover the whole interval.
tmp_1 =
SELECT
group_id,
CASE
WHEN valid_from = 20250201;
tmp_2 =
SELECT
group_id
FROM tmp_1
WHERE valid_from_min = 20250228
GROUP BY group_id;
This only works when a group has less than 3 entries.
Second row valid_from_min
will equal valid_from
of the first row - good.
Third row valid_from_min
will equal valid_from
of the second row - bad.
Aprikose
(11 rep)
Jul 4, 2025, 02:57 PM
0
votes
1
answers
838
views
How to install HANA DB on Oracle Linux 7?
I want to know how to install SAP HANA DB 2.0 on Oracle Linux 7 including downloading, installing and the first connection establishing to the system from network. I've spent a few hours to find out how to do it, but haven't found all required information in one place.
I want to know how to install SAP HANA DB 2.0 on Oracle Linux 7 including downloading, installing and the first connection establishing to the system from network. I've spent a few hours to find out how to do it, but haven't found all required information in one place.
Gryu
(305 rep)
Aug 28, 2020, 08:17 PM
• Last activity: Apr 12, 2025, 04:04 AM
1
votes
0
answers
444
views
Linked Server to Hana DB
I am trying to create a linked server connection from sql-server to Hana DB. I have downloaded the Hana client and all the drivers along with it. I have tried creating a system DSN and then adding the Hana database using the sp_addlinkedserver and sp_addlinkedsrvlogin procedures. This creates the li...
I am trying to create a linked server connection from sql-server to Hana DB. I have downloaded the Hana client and all the drivers along with it.
I have tried creating a system DSN and then adding the Hana database using the sp_addlinkedserver and sp_addlinkedsrvlogin procedures. This creates the linked server but when I expand into the server it show no catalogs (basically shows nothing).
Another way I tried was by hitting new linked server and using the SAP Hana MDX Provider and this shows me a default database. However when I expand the tables or views it gives me an error
Error image:
version: Sql-server-17
Cannot obtain the schema rowset "DBSCHEMA_TABLES" for OLE DB provider SAPNEWDBMDXProvider for linked server "NAME"
.
Any help will be greatly appreciated. Please let me know if you need any more information.

Rahul
(131 rep)
Jan 21, 2021, 04:20 PM
• Last activity: Jan 21, 2021, 05:59 PM
2
votes
1
answers
1163
views
What is a Compressed Prefix B+-Tree (CPBTree) in SAP HANA?
I'm studying the SAP HANA main memory database. There is an index called `CPBTree` in it. In its documentation, it is described as follows: > CPB+-tree stands for Compressed Prefix B+-Tree; this index tree type > is based on pkB-tree. CPB+-tree is a very small index because it uses > 'partial key' t...
I'm studying the SAP HANA main memory database.
There is an index called
CPBTree
in it. In its documentation, it is described as follows:
> CPB+-tree stands for Compressed Prefix B+-Tree; this index tree type
> is based on pkB-tree. CPB+-tree is a very small index because it uses
> 'partial key' that is only part of full key in index nodes.
This is a bit vague. There are no other explanations about the CPBTree's structure on the Internet.
Is there anyone who can provide an explanation more or refer me to good documentation/URLs/&c.?
Ali dashti
(123 rep)
Jun 15, 2020, 08:58 AM
• Last activity: Jun 16, 2020, 01:57 AM
0
votes
0
answers
903
views
MS SQL Linked Server to HANA 2.0 - error 10 authentication failed
I have some trouble setting up a linked server to a SAP HANA database. On the SQL-Server machine (SQL-Server 2019) i installed the ODBC drivers and set up a 64 System DSN. When I click on the "Test Connection" it succeeds. Driver version is 2.04.167.62361 I then Setup the Linked server as Follows: E...
I have some trouble setting up a linked server to a SAP HANA database.
On the SQL-Server machine (SQL-Server 2019) i installed the ODBC drivers and set up a 64 System DSN. When I click on the "Test Connection" it succeeds. Driver version is 2.04.167.62361
I then Setup the Linked server as Follows:
EXEC sp_addlinkedserver
@server='SAP',
@srvproduct='HANA',
@provider='MSDASQL',
@datasrc='HANA64'; --> Name of the ODBC DSN
EXEC sp_addlinkedsrvlogin
@useself = 'FALSE',
@rmtsrvname = 'SAP',
@locallogin = NULL,
@rmtuser = 'Readonly',
@rmtpassword = 'my_pwd';
It creates the Linked Server. When I test the connection in SSMS I get:
> [SAP AG][LIBODBCHDB DLL][HDBODBC] General error;10 authentication
> failed
All research on the internet did not get me further. Any Ideas?
My ODBC DSN Connection looks like follows:

Daniel
(121 rep)
Apr 29, 2020, 03:50 PM
• Last activity: Apr 29, 2020, 11:42 PM
0
votes
0
answers
41
views
Getting full (purpose, usage) Table names in SAP Hana
Each table in SAP Hana has a purpose, for example, `BSEG` is *Accounting Document Segment* and `BKPF` is *Accounting Document Header*. Is there anything in Hana (along the lines of `Select * From Tables`) _or_ a full list elsewhere on the Intertubes, that will get me the purpose\usage of each table...
Each table in SAP Hana has a purpose, for example,
BSEG
is *Accounting Document Segment* and BKPF
is *Accounting Document Header*.
Is there anything in Hana (along the lines of Select * From Tables
) _or_ a full list elsewhere on the Intertubes, that will get me the purpose\usage of each table in Hana?
I'm trying to put together a Workflow for Alfred that'll allow me to look up the definitions and it would be nice if I can get it to tell me "Look Up BSEG (Accounting Document Segment)" as I'm searching inside the workflow.
I've already got the list of names, just really could do with that purpose\usage if possible!
Rachel Ambler
(232 rep)
Apr 24, 2020, 03:32 PM
0
votes
1
answers
52
views
Select with a preffered where condition, but if missing use another
I have the following select in SAP HANA DB: SELECT name, text, lang FROM texts WHERE name IN ('name1', 'name2', 'name2') AND lang IN ( 'S', 'E' ) INTO TABLE @DATA(lt_texts). It will select multiple lines for a given name if translations exist for different languages. How do I say that I want texts w...
I have the following select in SAP HANA DB:
SELECT name, text, lang FROM texts
WHERE name IN ('name1', 'name2', 'name2')
AND lang IN ( 'S', 'E' )
INTO TABLE @DATA(lt_texts).
It will select multiple lines for a given name if translations exist for different languages.
How do I say that I want texts with language = 'S', but if it doesn't exist, then select ones with lang = 'E'. I want it in a single request to the DB and no processing on application level.
Thank you in advance
kdobrev
(101 rep)
Sep 30, 2019, 04:20 PM
• Last activity: Sep 30, 2019, 05:24 PM
0
votes
1
answers
6159
views
Cannot connect to an Hana database via its ODBC driver
I have not found any documentation about *ODBC* connection strings for *Hana* and am trying to connect using the [examples](https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.00/en-US/66a4169b84b2466892e1af9781049836.html) in *SAP HANA Database Client Interfaces*. An attempt to connect...
I have not found any documentation about *ODBC* connection strings for *Hana* and am trying to connect using the [examples](https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.00/en-US/66a4169b84b2466892e1af9781049836.html) in *SAP HANA Database Client Interfaces*.
An attempt to connect via *ODBC* with the connection string:
DRIVER=HDBODBC; SERVERNODE=192.168.0.213:30015; ID=SYSTEM; PWD=PASSWORD;
fails with this error:
ERROR [08S01] [SAP AG][LIBODBCHDB DLL][HDBODBC]
Communication link failure;
-10709 Connection failed (RTE: (192.168.0.213:30015))
whereas the corresponding *ADO.NET* connection works:
Server=192.168.0.213:30015;UserName=SYSTEM;Password=PASSWORD;
What may be wrong with the *ODBC* connection? I have the correct driver installed.
Anton Shepelev
(248 rep)
Dec 24, 2018, 09:22 AM
• Last activity: Apr 10, 2019, 05:50 AM
4
votes
2
answers
2309
views
How are these null values stored in a NOT NULL column?
We are replicating tables from SAP ECC 6.0 on HANA into an Oracle 10g warehouse, using SAP SLT. Since starting this, we have noticed the `NOT NULL` column definitions from HANA are retained in the Oracle copies of the tables, but HANA stores many values as empty strings. Oracle stores empty (varchar...
We are replicating tables from SAP ECC 6.0 on HANA into an Oracle 10g warehouse, using SAP SLT.
Since starting this, we have noticed the
NOT NULL
column definitions from HANA are retained in the Oracle copies of the tables, but HANA stores many values as empty strings. Oracle stores empty (varchar) strings as NULL
s and somehow this does not conflict with the NOT NULL
column definition (i.e. we have NULL
in a column defined as NOT NULL
).
Querying these tables is producing strange results:
SELECT COUNT(*) FROM warehouse.table WHERE col IS NULL;
0
SELECT COUNT(*) FROM warehouse.table WHERE col = '';
0
SELECT COUNT(*) FROM warehouse.table GROUP BY NVL(col,'N');
X 503206
N 2377222
So we can tell that there **are** NULL
values in these columns by using NVL
or DECODE
functions, but querying them is returning odd results.
We do get proper results once we alter the column:
ALTER TABLE warehouse.table MODIFY (col NULL);
Table altered.
SELECT COUNT(*) FROM warehouse.table WHERE col IS NULL;
390986
But of course we can't alter the column back:
ALTER TABLE warehouse.table MODIFY (col NOT NULL);
ERROR at line 1:
ORA-02296: cannot enable (warehouse.) - null values found
I can't tell if this is a problem with Oracle's implementation of empty string storage, or possibly just a quirk of interacting with SAP's SLT replication. It seems Oracle should not allow these rows with ''
or NULL
values as replication tries to place them there but we have not seen any errors indicating this.
---
Edit to add query requested by hypercube:
SELECT LENGTH(col) FROM warehouse.table GROUP BY LENGTH(col);
2377222
1 503206
Fredric Shope
(596 rep)
Nov 28, 2018, 03:19 PM
• Last activity: Nov 30, 2018, 04:38 AM
1
votes
0
answers
2000
views
HANA SQL procedure Iteration
Here is my requirement for a SAP HANA 2.0 system. 1) Identify users with not having SAML flag enabled from "SYS."USERS" table. Fields that I need from this table are USER_NAME,EXTERNAL_IDENTITY,IS_SAML_ENABLED. Sample data looks like this. USER_NAME EXTERNAL_IDENTITY IS_SAML_ENABLED. JDOE JDOE@aol.c...
Here is my requirement for a SAP HANA 2.0 system. 1) Identify users with not having SAML flag enabled from "SYS."USERS" table. Fields that I need from this table are USER_NAME,EXTERNAL_IDENTITY,IS_SAML_ENABLED. Sample data looks like this.
USER_NAME EXTERNAL_IDENTITY IS_SAML_ENABLED.
JDOE JDOE@aol.com TRUE
JDOE1 JDOE1@mail.com FALSE
JDOE2 JDOE@aol.com FALSE
2) If SAML is not enabled, I have to run these two SQL statements on each user ID in a loop until all those users identified in step 1 are updated and then close the loop. alter user JDOE enable SAML; alter user JDOE add identity 'JDOE' for SAML provider ;
SAML_PROVIDER variable comes from a table SAML_PROVIDERS that has multiple entries and and so on.
3) Another constraint is to map SAML to user based on their EXTERNAL_IDENTITY that has multiple values. This field is used for Kerberos authentication. So if first user has @aol.com then assign 'SAML_PROVIDER1' and if @mail.com is there then assign
4) I am looking to have this in a stored procedure because I would like to schedule this as a background job in HANA XS.
Here is the code that I tried to come up with after spending considerable amount of time and looking at information available online. Please note that I still not added the second SQL statement to the code. I am open to other suggestions that does not involve loop as long as I can do these tasks through a background job.
PROCEDURE ""."" ( )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
i INTEGER;
row_count INTEGER;
loop_current_SQL NVARCHAR(200);
valid_SAML NVARCHAR(5);
BEGIN
it_no_saml_users = SELECT DISTINCT
A."USER_NAME",A."IS_SAML_ENABLED",A."CREATOR"
FROM "SYS"."USERS" A
LEFT OUTER JOIN "SYS"."SAML_USER_MAPPINGS" B
ON (A."USER_NAME" = B."USER_NAME")
WHERE B."USER_NAME" IS NULL and A."CREATOR"='ADM' and
A."IS_SAML_ENABLED"='FALSE';
SELECT COUNT("USER_NAME") into row_count FROM :it_no_saml_users;
FOR i IN 0 .. :row_count -1 DO
SELECT "IS_SAML_ENABLED"
into valid_SAML FROM :it_no_saml_users
LIMIT 1 OFFSET :i;
IF :valid_SAML IS NULL THEN
SELECT 'ALTER USER' || "USER_NAME" || 'ENABLE SAML'
INTO loop_current_SQL
FROM :it_no_saml_users;
EXEC(:loop_current_SQL);
END IF;
END FOR;
END
When this procedure is ran, I do not get any error but number of rows affected is shown as 0.
I am new to SQL and please ignore if my procedure does not make sense.
Thank you.
RMR
(11 rep)
Aug 2, 2018, 02:14 PM
• Last activity: Aug 6, 2018, 01:46 PM
1
votes
1
answers
852
views
Select most recent row for each order
Currently writing a query which will be used to see where abouts on our production line a certain item is by showing what the last completed 'Resource' was. (resources on our system are just different areas of the assembly line eg, metal fabrication, spray shop, electrical wiring, testing etc.) I've...
Currently writing a query which will be used to see where abouts on our production line a certain item is by showing what the last completed 'Resource' was. (resources on our system are just different areas of the assembly line eg, metal fabrication, spray shop, electrical wiring, testing etc.)
I've written a query that gives me ALL completed resources on unfinished jobs, but as each job has several completed resources on it the table that gets output still needs refining.
SELECT
T0."DocNum",
T2."U_CustomerRef",
T1."DocNum",
T6."ItemCode",
CONCAT(T5."firstName", T5."lastName"),
T4."U_Time",
T4."U_Date",
T4."U_StopTime",
T4."U_StopDate"
FROM
ORDR T0 INNER JOIN RDR1 T2 ON T0."DocEntry" = T2."DocEntry"
LEFT OUTER JOIN "NL_LIVE"."OHEM" "OHEM" ON T0."OwnerCode"="OHEM"."empID"
LEFT OUTER JOIN OWOR T1 ON T1."OriginAbs" = T0."DocEntry" AND T2."ItemCode" =T1."ItemCode"
INNER JOIN WOR1 T6 ON T1."DocEntry" = T6."DocEntry"
INNER JOIN OITM T3 ON T2."ItemCode" = T3."ItemCode"
LEFT OUTER JOIN "NL_LIVE"."@OCHLABBOOK" T4 ON T4."U_ProdOrderNo" = T1."DocNum" AND T4."U_ProdOrderLine"=T6."LineNum"
LEFT OUTER JOIN "NL_LIVE"."OHEM" T5 ON T4."U_StartEmp"=T5."U_UniqueID"
WHERE
T0."DocStatus"='O'
AND T6."ItemType"=290
AND T4."U_Action"'Started' AND T4."U_Action"'Stopped' AND T4."U_Action"'Paused'
I've tried doing SELECT MAX on the results using the date and time, but that leaves me with only one result in the table as there aren't any groupings for each area it just gives me the latest results for the whole table not each individual job/Document. In this image you can see I've drawn red borders showing that certain parts should be grouped, essentially what i need is a way of selecting the most recent date from each smaller group of data within the Query. Each subset needs to be grouped by Document number (column 3 document number not column 1)
**Large shaded red area is just to cover employee names and isn't relevant to the question**
Thanks in advance for any help given. If more information is required I can go into more detail of table structures etc.

KnightLeaf
(11 rep)
Nov 9, 2017, 04:02 PM
• Last activity: Nov 14, 2017, 07:07 AM
0
votes
1
answers
836
views
Data Join with offset
I have below situation: **`Table1`** Field1 Field2 123 test1 234 test2 **`Table2`** Field1 Field2 12345 test2 23245 test3 123945 test6 I want to join these two tables i.e. `Table1` and `Table2` where `Field1` of `table1` matches with first three characters of `field1` of `table2`. So results here sh...
I have below situation:
**
Table1
**
Field1 Field2
123 test1
234 test2
**Table2
**
Field1 Field2
12345 test2
23245 test3
123945 test6
I want to join these two tables i.e. Table1
and Table2
where Field1
of table1
matches with first three characters of field1
of table2
.
So results here should be:
Table1-field1 Table1-field2 Table2-field1 Table2-field2
123 Test1 12345 Test2
user134806
(1 rep)
Sep 17, 2017, 07:32 PM
• Last activity: Oct 18, 2017, 01:21 PM
2
votes
1
answers
3248
views
Can you use ODBC to extract data directly from SAP HANA S/4 1610?
Trying to get a handle on what's possible and what's not with SAP Hana S/4 1610. My understanding is that one can access the underlying SAP HANA DB via ODBC simply by utilzing the SAP HANA Client which installs the ODBC Driver required. Once installed one can, from what I read, access the vast data...
Trying to get a handle on what's possible and what's not with SAP Hana S/4 1610.
My understanding is that one can access the underlying SAP HANA DB via ODBC simply by utilzing the SAP HANA Client which installs the ODBC Driver required. Once installed one can, from what I read, access the vast data stores that power the SAP ERP via standard ODBC calls using tools such as SSIS.
However I'm being told conflicting information from other people on if this is even possible and that what is really required is for the vendor to be in control of that process and for them to write apps in ABAP that will interrogate the underlying DB and deliver unto us flat files which our ETL process will then use.
We'll be using a locally hosted SAP HANA installation so, not on prem but no cloudy either.
**Clarification:** All I need here is a yes, you can connect to SAP HANA S/4 1610 via ODBC or no, you can't and another method is required.
TBH not really interested in the how either since everything else I've read online tells me that. However when you've $10bn a hour consultants saying no, one has to question reality.
Rachel Ambler
(232 rep)
Mar 16, 2017, 04:55 PM
• Last activity: Oct 12, 2017, 05:37 PM
1
votes
1
answers
93
views
Find addresses shared by more than one customer_id where customer_name is is distinct
I need to return the list of addresses that have more than one customer_ID associated with them, exclude the customer_IDs that have the same customer_name and return the number of time the address repeats Here is what the data looks like: CUSTOMER_ID | CUSTOMER_NAME | ADDRESS | MEMBER_SINCE --------...
I need to return the list of addresses that have more than one customer_ID associated with them, exclude the customer_IDs that have the same customer_name and return the number of time the address repeats
Here is what the data looks like:
CUSTOMER_ID | CUSTOMER_NAME | ADDRESS | MEMBER_SINCE
----------------------------------------------------------------------
A1000 | John Doe | 123 West Lane | 2/23/2005
A1001 | John Doe | 123 West Lane | 9/30/2005
A1002 | Tom White | 456 East Street | 5/7/2006
A1003 | Frank Smith | 123 West Lane | 12/12/2006
A1004 | Lisa Simpson | 456 East Street | 7/19/2007
A1005 | Clark Kent | 700 North Ave. | 2/23/2008
A1006 | Darth Vader | 123 West Lane | 9/29/2008
A1007 | John Doe | 456 East Street | 5/23/2007
A1008 | Bart Star | 456 East Street | 4/19/2006
I want the result set to look like:
CUSTOMER_ID | CUSTOMER_NAME | ADDRESS | MEMBER_SINCE| COUNT
--------------------------------------------------------------------------------
A1000 | John Doe | 123 West Lane | 2/23/2005 | 3
A1002 | Tom White | 456 East Street | 5/7/2006 | 4
A1003 | Frank Smith | 123 West Lane | 12/12/2006 | 3
A1004 | Lisa Simpson | 456 East Street | 7/19/2007 | 4
A1006 | Darth Vader | 123 West Lane | 9/29/2008 | 3
A1007 | John Doe | 456 East Street | 5/23/2007 | 4
A1008 | Bart Star | 456 East Street | 4/19/2006 | 4
The result shows the CUSTOMER_IDs, CUSTOMER_NAMES, ADDRESSES, MEMBER_SINCE and the COUNT of distinct CUSTOMER_IDs that share the address, while ignoring the rows that have same ADDRESS and CUSTOMER_NAME as another row even though the CUSTOMER_ID is different. Any ADDRESSES that do not have more than one CUSTOMER_ID are also excluded.
Notice that CUSTOMER_ID A1001 is absent in the result since the CUSTOMER_NAME and ADDRESS are the same and must be a duplicate, and A1005 is absent since there are no other customers with that address.
This is the start:
SELECT
CUSTOMER_ID as CUSTOMER_ID,
"CUSTOMER_NAME" as CUSTOMER_NAME,
"ADDRESS",
"MEMBER_SINCE",
count(CUSTOMER_ID) as COUNTER
FROM CUSTOMER_TABLE
group by ADDRESS_ID, CUSTOMER_ID, CUSTOMER_NAME
having
count(CUSTOMER_ID)>1
order by CUSTOMER_ID;
But I can't manage to take out the duplicate CUSTOMER_NAMES.
This is my first post here and it is very late for me, so I apologize in advance if I didn't post the question correctly.
AR
user100188
(13 rep)
Jul 15, 2016, 08:43 AM
• Last activity: Jul 15, 2016, 09:16 AM
2
votes
1
answers
6751
views
Find columns with different values compared with a reference row
My table, MARC, has more than 200 columns with WERKS (plant) as the key. Most of the entries in MARC have values that come from a *reference plant*. So, usually, all the 200 columns will contain the same values. I need to find the columns that have different values compared with the reference plant...
My table, MARC, has more than 200 columns with WERKS (plant) as the key.
Most of the entries in MARC have values that come from a *reference plant*. So, usually, all the 200 columns will contain the same values.
I need to find the columns that have different values compared with the reference plant row, in order to find the deviations and show the names of the columns that had different values.
The main question is: how to do the select when it is not known which columns need to be selected.
### Example
In the above, ABAS is the reference plant.
I expect only the first row to be returned, because only that row contains any differences compared with the reference row. Differences in that row occur in the following columns:
* WERKS
* PSTAT
* DISMM
* DISPO
The returned row should contain *only those four columns*.
I do not need any other columns to be able to show on the UI that these 3 columns have different values for that particular WERKS.
I am using SAP HANA.

user2293813
(31 rep)
Aug 14, 2015, 11:23 AM
• Last activity: Aug 15, 2015, 05:51 PM
Showing page 1 of 15 total questions