Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
declare @string nvarchar(255) = 'C20000'
declare @fdate DATE = '220106'
declare @tdate DATE = '220106'

select sum("DocTotal") from OINV where OINV."CardCode" like '%'+ 'C20000' +'%' and cast(@fdate as date) between cast(@fdate as date)
and cast(@tdate as date)

What I have tried:

HELP ME ON QUERY CORRECTION FOR HANA / SQL.

This query gives error result like kindly check declare statement. Need to help on query proper correction and development.
Posted
Updated 1-Feb-21 0:31am
v2
Comments
OriginalGriff 29-Jan-21 6:37am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

Use the "Improve question" widget to edit your question and provide better information.
Nik12721 29-Jan-21 6:41am    
I am getting error while execute query. Getting error on declare statement.
OriginalGriff 29-Jan-21 6:58am    
Which declare statement?
What have you tried to find out why?
What happened when you did?
Where are you running this? How?

If I try them in standard SQL via SSMS is works fine. So you need to explain what exactly you are doing, and what *exactly* happens when you do. At the moment all you are doing is going "it don't work" and expecting people who can't see your screen to know why ...
Nik12721 29-Jan-21 7:59am    
Run it in HANA and you are see the errors please
[no name] 29-Jan-21 10:28am    
Why are you casting a "date" as a "date"?

1 solution

Quote:
Run it in HANA and you are see the errors please
Nope - can't afford it. In the meantime why don't you just tell us which of the declare statements causes an issue? Help us to help you.

I'm going to hazard a guess that it's this line that it's moaning about
SQL
declare @fdate DATE = '220106'
What date is that meant to be? 1st June 2022 or 6th January 2022 or perhaps 1st June 1922. Use ISO 8601 date format[^] to remove the confusion and it might just solve your problem e.g. for 6th June 2022 use
SQL
declare @fdate DATE = '20220106'
A better place to get support on this would be the Help Portal from SAP - see SAP Help Portal[^]

Edit: I feel I should also pick up on the comment from Gerry Schmitz (@salty06) - this code
SQL
select sum("DocTotal") from OINV where OINV."CardCode" like '%'+ 'C20000' +'%' and cast(@fdate as date) between cast(@fdate as date)
and cast(@tdate as date)
contains some pointless casts. @fdate and @tdate are already dates. There is no need for the cast. So, use
SQL
select sum("DocTotal") from OINV where OINV."CardCode" like '%'+ 'C20000' +'%' and @fdate between @fdate and @tdate
Which then just highlights another issue - @fdate will ALWAYS be between itself and another date. You probably meant to use a column name there
SQL
select sum("DocTotal") from OINV where OINV."CardCode" like '%'+ 'C20000' +'%' and [aColumnName] between @fdate and @tdate
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900