Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SQL Query using DATS data type

Former Member
0 Likes
1,348

Hello people,

I have a table 'TableA' with a column 'xpto' that has DATS data type.

A lot of lines in this table has this field empty.

I have to create a SQL query to select those lines with this field not empty.

Select * from TableA

where xpto is not null

It does not work.... The result is all the lines in the table.

What is wrong?

Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,133

This works:


DATA: dt LIKE sy-datum.

SELECT SINGLE * FROM bkpf WHERE budat <> dt.

Rob

6 REPLIES 6
Read only

Former Member
0 Likes
1,133

select * from tableA where xpto = ''.

Read only

0 Likes
1,133

select * from tableA where xpto ne ''.

Read only

0 Likes
1,133

I have already tried

ne ''

<> ''

and those ones dont work too........

Read only

Former Member
0 Likes
1,133

Easiest way to do this is :

constants l_xpto type tableA-xpto value is initial

Select * from TableA

where xpto ne l_xpto.

You can see the NULL/NOT NULL settings for the column through SE11

Utilities -> Database Object -> Display.

I tend to set the "Initial Value" flag when adding columns to tables, which creates the database column as NOT NULL with a default value (whatever SAP considers the initial value for that datatype). I think SAP does this by default, but I've had issues where it hasn't so I do this to ensure consistency

Chris Bain

Read only

Former Member
0 Likes
1,134

This works:


DATA: dt LIKE sy-datum.

SELECT SINGLE * FROM bkpf WHERE budat <> dt.

Rob

Read only

Former Member
0 Likes
1,133

Thanks a lot everybody!

When I create a blank variable, it works!