Execute Hana stored proc with input parameters in ssrs - stored-procedures

I cannot seem to get a HANA Stored Procedure to work with input parameters in SSRS by passing parameters via CALL:
Actuaaly my problem is either SSRS or the ODBC driver is having a problem sending/receiving the parameter value.
Other attempts at syntax: call "sp_getdata"() , call "sp_getdata"(?) , call "sp_getdata"(regid) , call "sp_getdata"(#regid)
None of these worked.
If I call the procedure with a hard coded value i.e. call "sp_getdata"(5) - it works.
Again, if the stored procedure has no parameters it works fine.
Can anyone give me any real direction on this issue. A sample of the correct syntax or a step by step example would really be appreciated.

Create the syntax in the Dataset Expression from the Parameter instead of letting SSRS insert the parameter call "sp_getdata"(?)
Use the Expression in the Dataset's Command Text box.
="Call " & CHR(34) & "sp_getdata" & CHR(34) & "(" & Parameters!REG_ID.Value & ")"
The resulting text passed to the server would be (with X for the number):
Call "sp_getdata"(x)

Related

Stuck on a basic Lua writeInteger function

I am a newcomer to coding in general and I want to learn basic Lua scripting for my own hobby.
After working on a Lua script, the syntax all seems to be without error but I have come across one issue that I don't understand, I broke it down to this basic function:
{$lua}
ID1 = "10"
ID2 = "0"
if (ID1 ~= nil and ID1 == "10") then
writeInteger(ID2,"25")
end
print(ID2)
The issue is that the writeInteger does not seem to work at all, ID2 remains at value "0" while it should become "25".
Any help would be greatly appreciated.
This is not valid Lua, or at least it isn't valid vanilla (out-of-the-box) Lua, and since you have not specified anything else, there is not much we can do to help. I will assume writeInteger is a valid function (since your interpreter isn't complaining about a call to a nil value), but I don't think it works as you expect.
If you want to set the ID2 variable to 25, simply write:
ID2 = 25
Lua will convert the string type to an integer type automatically. You can run print(type(ID2)) to confirm this
If you are using cheat engine (as a quick google search suggests) the writeInteger function requires an address and a value.
function writeInteger(Address, Value): Boolean - Returns true on success.
I am not sure if ID2, a Lua variable, is a valid address, but I am sure that "25" is not an integer. You should remove the quotation marks to start, and since the function returns a boolean you can see if the function was successful by doing:
print(writeInteger(ID2, 25))
Lua uses pass by value for primitive types like numbers, booleans and strings. So if you pass a number to a function like writeInteger, it creates a local copy within the function. The function can alter this copy but it will have no effect on caller (of writeInteger in this case). I don't know how writeInteger is supposed to work but if you want to call a function which alters its argument you can create a table and pass that. Tables are still passed by value but the "value" of a table is its memory address (so in effect tables are passed by reference and you can alter the contents of a table by passing it to a function).
See more here
Function/variable scope (pass by value or reference?)

Firedac select working with Firebird returns no records

Hello I'm working with Firedac (Delphi Seattle) using Firebird (2.5) as a database, when I run this query using a TFDQuery, no records are returned:
SELECT ID FROM USERS WHERE PWD = 'êHÆ–!+'
The same query within a Database program as IbExpert return one record. Is there some parameter with Firedac components to configure that can solve this issue. Thanks.
It's in the query string and it's the ! char. By default, query strings are preprocessed, and you must escape constant chars like !, &, :, ?, { or }, otherwise they are used as special chars.
Your best option is using parameters. That will (except other benefits) get rid of that ! char from the preprocessed command:
FDQuery.SQL.Text := 'SELECT ID FROM USERS WHERE PWD = :Password';
FDQuery.ParamByName('Password').AsString := 'êHÆ–!+';
FDQuery.Open;
Another option is escaping that constant char or disable macro preprocessor. For more information see the Special Character Processing topic.

Figuring out what this Trim() function is doing?

I have a constraint on a transformer with this:
Trim(CollectFrom.collect_from,"-","A")<=TheDate
Here is what collect_from looks like:
'2017-02-27'
And here is what TheDate looks like:
'20170227'
I am unsure exactly how this Trim() function works. My first guess is that it is giving it the same format as 'TheDate' however I don't understand the "A" argument. Could somebody explain it?
The manual page for TRIM() says that shouldn't work.
When I try to run what you show, I get errors:
SQL[2405]: select trim('2017-02-01', '-', 'A') from dual;
SQL -674: Routine (trim) can not be resolved.
SQLSTATE: IX000 at /dev/stdin:1
SQL[2406]: select trim('2017-02-01', '-') from dual;
SQL -674: Routine (trim) can not be resolved.
SQLSTATE: IX000 at /dev/stdin:2
The manual says you need TRIM({BOTH|LEADING|TRAILING} [char] FROM source):
SQL[2407]: select trim(both '-' from '2017-02-12') from dual;
2017-02-12
SQL[2408]: select trim(both '-' from '2017-02-12-') from dual;
2017-02-12
SQL[2409]: select trim(both '-' from '-2017-02-12-') from dual;
2017-02-12
SQL[2410]:
(The SQL command interpreter used is my SQLCMD.)
There's a chance that someone has defined a TRIM function that takes three arguments — that's not detectable from here. You'd have to look in the system catalog of your database to find that.
OTOH, that doesn't seem to be allowed, either:
SQL[2411]: create function trim(a varchar(10), b varchar(20), c varchar(30)) returning varchar(64);
return trim(leading from a) || ' ' || trim(both from b) || ' ' || trim(trailing from c);
end function;
SQL -9710: Overloading of built-in functions is not allowed.
SQLSTATE: IX000 at /dev/stdin:8
SQL[2412]:
Informix 11.50 has build in trim() function: https://www.ibm.com/support/knowledgecenter/SSGU8G_11.50.0/com.ibm.sqls.doc/ids_sqs_1556.htm But it looks little different from trim() in your question, so I think you use trim() function build by some user.
Normally trim() takes care only at chars at beginning or at end of the string, but in your example trim() had to remove - chars that are in the middle of the string. I guess that last argument A tells trim() to remove all such characters from source string.
To find out what trim() function really do you must find it source. You can do it with some GUI database tools like SQirreL SQL Client (it uses JDBC), you can do it with dbschema Informix utility or with my Python/Jython program that uses ODBC/JDBC: https://code.activestate.com/recipes/576621-dump-informix-schema-to-text
It would be helpful to tell us what version of Informix you use.
Trim(CollectFrom.collect_from,"-","A")
Here A means to Remove all the occurrences of '-' from the input string CollectFrom.collect_from . Hence You are getting '20170227' . Here is the document which would give further more information on Trim function.
https://www.ibm.com/support/knowledgecenter/en/SSZJPZ_11.5.0/com.ibm.swg.im.iis.ds.parjob.dev.doc/topics/r_deeref_String_Functions.html

Add days to date in SAP HANA stored procedure

I need to add days to date in HANA stored procedure, but I am getting error message
ERROR WHILE parsing DATE/ TIME
I use this statement where p_end_date is parameter of my stored procedure.
v_end_date_plus := add_days (TO_DATE(' || p_end_date || ' , 'YYYY-MM-DD' ), 90)
Is there is any other way or what I am doing wrong in it ?
Even though you didn't post what error you receive, I guess that the problem in your code is the way you referenced your input variable.
v_end_date_plus := add_days ( :p_end_date , 90);
With the colon (:) in front of the parameter you should be able to use it without having to cast it into a different data type.
#LarsBr. is correct that you need a colon (:) to reference the variable, and that if it is really a DATE type, you don't need to convert TO_DATE again.
But additionally, in your example you have some mixup with quotes and concatenation that makes me think that you actually want to construct some character string using p_end_date. This would need conversion to a date first:
p_end_date := '2016-05-03'; -- for example
v_end_date_plus := add_days(TO_DATE( :p_end_date , 'YYYY-MM-DD' ), 90);
The part ' || p_end_date || ' in your example also looks a bit like the whole code was actually part of string to be used in EXEC or similar. If that's the case, you need to have escaped single-quotes for both parameters, e.g.
exec 'v_end_date_plus := add_days(TO_DATE(''' || :p_end_date || ''', ''YYYY-MM-DD'' ), 90)';
p_end_date should be a varchar field, or the appropriate string literal used in your technology. It should not be enclosed in quotes.
v_end_date_plus := add_days (TO_DATE(p_end_date , 'YYYY-MM-DD' ), 90)
EXPLANATION USING ORACLE AS REFERENCE :
In Oracle database, the default date format is dd-MON-RR or dd-MON-YYYY.
So, if I use correct date format to p_end_date variable, I am able obtain output.
However, if I diverge from this default format,my attempt would error out.
So, if I want the flexibility to redefine p_end_date in format of my choice, and not as per default settings, it should be a String literal.(varchar in Oracle ).
EDIT:
The essence of this answer was just to suggest that the variable should be passed as a varchar. Borrowing from Lars Br's suggestion below to modify the p_end_date variable's syntax:
v_end_date_plus := add_days (TO_DATE(:p_end_date , 'YYYY-MM-DD' ), 90)

Execute immediate 'Create or replace view' gives 00900. 00000 - "invalid SQL statement" error

I have been stuck with this error. Can you please suggest what the mistake is in the code below? This is written inside a procedure that takes input for the variables. Thanks.
execute immediate 'Create or replace view '||p_viewname||' AS
select * from (
select NAME, CODETYPE, CODE
from HLIDEV_VIEWS.V_CONCEPT
WHERE HLIDEV_VIEWS.V_CONCEPT.CONCEPTTYPE = '''||p_concepttype||'''
)
pivot
(
max(code)
for codetype in ('||all_codetypes||')
)';
Update: Below is the error I am seeing.
EXEC "HLIDEV_VIEWS"."FinalCreatePOAView" ('POA_CONCEPT_TYPE','PresentOnAdmission')
Error report -
ORA-00911: invalid character
ORA-06512: at "HLIDEV_VIEWS.FinalCreatePOAView", line 39
ORA-06512: at line 1
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
What you are trying to do is perfectly doable using execute immediate. You just have a syntax error somewhere or the table really doesn't exist.
Try writing the string you are building to DBMS_OUTPUT.PUT_LINE instead of sending it to EXECUTE IMMEDIATE. Then, try to run that string as a command in SQL*Plus. That should highlight the error.
FWIW, I don't have your objects in my database, but I wrote an EXECUTE IMMEDIATE with the same form as yours and it works fine in Oracle 11g2.
DECLARE
p_view_name VARCHAR2(61) := 'VXSMIMMCP.MATT_V';
p_region_code VARCHAR2(30) := 'R01';
p_all_port_codes VARCHAR2(400) := '''P01'',''P02'',''P03''';
BEGIN
EXECUTE IMMEDIATE
'Create or replace view '
|| p_view_name
|| ' AS select * from ( select REGION_CODE, account_number , port_code from APPS.XXCUS_ACCOUNTS WHERE APPS.XXCUS_ACCOUNTS.REGION_CODE = '''
|| p_region_code
|| ''' ) pivot ( min(account_number) for port_code in ('
|| p_all_port_codes
|| ') )' ;
END;
Thank you #MatthewMcPeak and #MahendarMahi for your inputs. Suddenly my code started working fine and it created the view the way I wanted. The only thing I did was, as #MahendarMahi suggested, I removed pivot and ran it to see the same error and then replaced pivot and the error was gone. I am sure there is no change in the code but anyhow it weirdly works now. Thank you again for your time.

Resources