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

how to write the select query with complex where condition

Former Member
0 Likes
1,188

Hi all,

Can u help me in writing following select query.

select * from zu1cd_corr where time_stamp between firstday and lastday .

In the above query time_stamp contains the date and time.

where as firstday and lastday contains the dates.

I need to compare the date in the time_stamp with the firstday and lastday.

But time_stamp contains the time also and it is char of 14 characters length.

1 ACCEPTED SOLUTION
Read only

former_member404244
Active Contributor
0 Likes
1,075

Hi,

Then split the time stamp into date and time and put in variables and then write ur query..

lv_date = time_stamp+0(8).

lv_time = time_stamp+8(6).

if lv_Date GT Firstday AND lv_Date LT Lastday

select * from zu1cd_corr into table it_zu1cd_corr.

endif.

Regards,

Nagaraj

6 REPLIES 6
Read only

Former Member
0 Likes
1,074

Hi,

You can write where condition "date GE lowervalue and date le highervalue"

"time GE lowervalue and time le highervalue"

Read only

former_member404244
Active Contributor
0 Likes
1,076

Hi,

Then split the time stamp into date and time and put in variables and then write ur query..

lv_date = time_stamp+0(8).

lv_time = time_stamp+8(6).

if lv_Date GT Firstday AND lv_Date LT Lastday

select * from zu1cd_corr into table it_zu1cd_corr.

endif.

Regards,

Nagaraj

Read only

0 Likes
1,074

problem is that time_stamp is a field in the table.

Read only

0 Likes
1,074

Hi,

Concatenate the time 000000 to the firstday and 240000 to the lastday. This way you will get everything that is between first day starting at midnight until last day midnight.

regards,

Advait

Read only

0 Likes
1,074

Hi,

If that is the case u can do as advait specified....

if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.

CLEAR : lv_firstday,

lv_lastday.

concatenate firstday '000000' to lv_firstday.

concatenate lastday '240000' to lv_lastday.

ranges : r_Date for zu1cd_corr-time_stamp.

r_date-sign = 'I'.

r_date-option = 'BT'.

r_Date-low = lv_firstday.

r_Date-high = lv_lastday.

append r_date.

select * from zu1cd_corr into table it_zu1cd_corr where time_stamp in r_Date.

I hope it helps.

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,074

Hey leela,

*First select all the data from zulcd_corr table.

select * from zu1cd_corr into table it_zu1cd_corr.

*then,

loop at it_zu1cd_corr where ls_zu1cd_corr.

*Then split the time stamp into date and time and put in variables and then write ur query..

lv_date = ls_zu1cd_corr-time_stamp+0(8).

lv_time = ls_zu1cd_corr-time_stamp+8(6).

*check as per your condition

if lv_Date GT Firstday AND lv_Date LT Lastday

*append it to another internal table.

endif.

endloop.

i hope this will solve your problem.

Regards,

N M Poojari.