SQL Statement not works using functions or subqueries-MAXDB
Hello All,
I created an ABAP program to select information about country(table: T005) with the country names (Table: T005T). I tried to create a sql query with a sql subquery to select everything but for some reason that I don't know it doesn't work. Please find the query below.
DATA:
resu TYPE REF TO cl_sql_result_set ,
stmt TYPE REF TO cl_sql_statement ,
qury TYPE string .
qury = `SELECT land1, spras, `
&& `(SELECT landx `
&& `FROM SAPNSP.T005T `
&& `WHERE mandt = '` && sy-mandt && `' `
&& `AND spras = 'EN' `
&& `AND land1 = ? ), `
&& `(SELECT natio `
&& `FROM SAPNSP.T005T `
&& `WHERE mandt = '` && sy-mandt && `' `
&& `AND spras = 'EN' `
&& `AND land1 = ? ) `
&& `FROM SAPNSP.T005 `
&& `WHERE mandt = '` && sy-mandt && `' `
&& `AND land1 = ? `
&& `GROUP BY land1, spras` .
resu = stmt->execute_query( qury ) .
Well, the query above works but the fields LANDX and NATIO are in blank in ALL THE CASES, even with information registred in table T005T.
So, exploring the SDN forum and after read some documents regarding ADBC, I create a function to handle this sql select and get the correctly the missing informations, but, still don't work. Please find the function below:
CREATE FUNCTION select_landx (land1 CHAR(3)) RETURNS CHAR(15)
AS
VAR landx CHAR(15);
DECLARE functionresult CURSOR FOR
SELECT spras, land1, landx
FROM SAPNSP.t005t
WHERE spras = 'EN'
AND land1 = :land1;
IF $count IS NULL THEN <- | $count is always 0, my SELECT
BEGIN it's not work but I don't know why
CLOSE functionresult;
RETURN NULL;
END
ELSE
SET $rc = 0;
WHILE $rc = 0 DO
BEGIN
FETCH functionresult INTO :landx;
END;
CLOSE functionresult;
RETURN landx;
Calling the function in a SQL statement:
DATA:
resu TYPE REF TO cl_sql_result_set ,
stmt TYPE REF TO cl_sql_statement ,
qury TYPE string .
qury = `SELECT land1, spras, select_landx(?) landx `
&& `FROM SAPNSP.T005 `
&& `WHERE mandt = '` && sy-mandt && `' `
&& `AND land1 = ? `
&& `GROUP BY land1, spras` .
resu = stmt->execute_query( qury ) .
Any comments ?
Best regards,
Arthur Silva
Hello,
Thank's a lot, it works. It's funny because the given solution works using only abap codes.
It may be happens because the abap interpretor send the sql statement to the db interface that handle the code in the another way.
Thanks again, it was driving me crazy.
Best regards,
Arthur Silva
Similar Messages
-
Sender JDBC adapter -- Update SQL statement NOT work for the last record
I'm trying to use SAP XI to send records from Oracle database to As/400 using JDBC adapter. I've defined the communication channel for sender
(1) The "Query SQL statement" = select a_bgn_dt, a_end_dt from PX_PXXD WHERE NOT CU_ACTION_CD='P'
(2) The "Update SQL statement" = update PX_PXXD set CU_ACTION_CD='P' WHERE NOT CU_ACTION_CD='P'
Supposed that 3 records were retrieved from (1) and successfully updated to AS/400 but only the first 2 records in Oracle database are updated according to (2)
Any advise.
PansyHi Pansy,
You select and update query is looking like wrong
kindly check below query,If you are using oracle
(1) The "Query SQL statement" = select a_bgn_dt, a_end_dt from PX_PXXD WHERE CU_ACTION_CD !='P'
(2) The "Update SQL statement" = update PX_PXXD set CU_ACTION_CD='P' WHERE CU_ACTION_CD !='P'
Thank you
Sateesh -
SQL statement not working for an application
Hello,
Here is a sql statement which i am using to populate Department ID using another row in the table. Using these I am getting the values called department alias from different table and schema.
UPDATE tablename_4127 PT
SET "Deptid" = (select distinct(deptid) from datastore.get_department_alias
where upper(ltrim(rtrim(deptalias))) = upper(ltrim(rtrim(PT."Dept Descr")))
AND "Colid" = PT.COLID)
Please anyone help me with this.
Thank youHBUA wrote:
Hello,
Here is a sql statement which i am using to populate Department ID using another row in the table. Using these I am getting the values called department alias from different table and schema.
UPDATE tablename_4127 PT
SET "Deptid" = (select distinct(deptid) from datastore.get_department_alias
where upper(ltrim(rtrim(deptalias))) = upper(ltrim(rtrim(PT."Dept Descr")))
AND "Colid" = PT.COLID)
Please anyone help me with this.
Thank youhelp you how, since we don't have your table, data or requirements?
How do I ask a question on the forums?
SQL and PL/SQL FAQ -
Sql statement not working with for update
Hi, iam facing an error fetch out of sequence
when iam trying to execute a sql statement
Statement st=con.createStatement();
st.executeQuery(select mycolumn from table where jobno=1 for update);
the statement works well without " for update ".
any solutions????Hi,
The fetch out of sequence error occurs usually when you are trying to read from a cursor that has no data left(like EOF).
After executing the sql statement move the pointer to the first row (or the beginning of the resultset)
This is actually an oracle error bearing number :ORA:01002
Hope this helps.
Thanks,
Creator Team. -
Using EXECUTE IMMEDIATE with Create Table SQL Statement not working
Hi ,
I am all the privileges given from the SYSTEM user , but still i am not able to create a table under procedure . Please see these and advice.
create or replace procedure sp_dummy as
begin
Execute Immediate 'Create table Dummy99_99 (Dummy_Field number)';
end;
even i tried this way also
create or replace PROCEDURE clearing_Practise(p_file_id in varchar2, p_country in VARCHAR2,p_mapId in VARCHAR2)
AUTHID CURRENT_USER AS
strStatusCode VARCHAR2(6);
BEGIN
EXECUTE IMMEDIATE 'create table bonus(name varchar2(50))';
commit;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('ERROR Creating Table');
END ;William Robertson wrote:
Since the syntax is correct, my guess is you do not have CREATE TABLE system privilege granted directly to your account. A common scenario is that you have this privilege granted indirectly via a role, allowing you to create tables on the command line, but stored PL/SQL is stricter and requires a direct grant and therefore the procedure fails with 'insufficient privileges'.A bit like he's already been told on his first thread...
Using of Execute Immediate in Oracle PLSQL
Generally you would not create tables from stored PL/SQL. Also as you have found out, it's best not to hide exceptions with 'WHEN OTHERS THEN [some message which gives less detail than the one generated by Oracle]'.Again like he was told on the other thread.
There's just no telling some people eh! :) -
T sql dose not work in SQlCompact
im useing a T Sql in SQlCompact database but
it dose not work the function is stuff() that forgathering values in on
cell this is the select
Statement but it shows me an error asking
for help
SELECT Pepole.ID,
Pepole.FNA, Pepole.LNA, STUFF ((SELECT ', ' + Name AS Expr1 FROM Special AS S2 WHERE (ID = PeopleTarget_1.SpecialID) FOR XML PATH('')),,,) AS Names FROM Pepole INNER
JOIN PeopleTarget AS PeopleTarget_1 ON Pepole.ID = PeopleTarget_1.PeopleID INNER JOIN Special
AS Special_1 ON PeopleTarget_1.PeopleID = Special_1.IDSELECT Pepole.ID, Pepole.FNA, Pepole.LNA, STUFF
((SELECT ', ' + Name AS Expr1
FROM Special AS S2
WHERE (ID = PeopleTarget_1.SpecialID) FOR XML PATH('')),,,) AS Names
FROM Pepole INNER JOIN
PeopleTarget AS PeopleTarget_1 ON Pepole.ID = PeopleTarget_1.PeopleID INNER JOIN
Special AS Special_1 ON PeopleTarget_1.PeopleID = Special_1.ID -
Force encryption on SQL Server not working?
Hello Everyone,
I'm running SQL Server 2008 64-bit. I've installed a self-signed cert on the box and set "Force Encryption" and restarted SQL server.
I setup a client machine to trust the authority of the cert installed on the server. When I connect to that SQL server from SSMS from a client machine and select the "encrypt connection" option in the client Connection properties, SSMS correctly complains
that the cert on the server does not match the computer name I asked to log into . This is because, although the cert is trusted, the dns name dos not match the CN in the cert <- Perfect, exactly what I am expecting.
When I connect to the same SQL server from the same client but UNCHECK "encrypt connection" on the client, I'm able to login. Considering I've checked the "Force Encryption" on the server, the server should have rejected the connection. Why not?
Ameer DeenHi all,
We are implementing a Merge Synchronization solution which involves three SQL Servers located on three Azure locations worldwide and one on-premises location. We need to secure communications between all servers. We are evaluating the encryption of all server
communications through SSL:
http://technet.microsoft.com/en-us/library/ms191192.aspx
When we configure one server (let’s call it server A) to accept only encrypted connections (with Force Encryption=Yes) we still can connect from other server (let’s call it server B) that do not have the certificate installed. We would expect the server
B to fail in the attempt of connect as server A should only accept encrypted communications and those should need the certificated to encrypt/decrypt everything (commands and data).
We have also review the following forum post that is very similar to this one:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/bde679d9-ff83-4fa7-b402-42e336a97106/force-encryption-on-sql-server-not-working
In all cases the Microsoft answer is:
“When the
Force Encryption option for the Database Engine is set to YES, all communications between client and server is encrypted no matter whether the “Encrypt
connection” option (such as from SSMS) is checked or not. You can check it using the following DMV statement”
When we run the provided DMV statement to check if encryption is enabled:
-- To check whether connections are encrypted between server and clients
SELECT encrypt_option
FROM sys.dm_exec_connections
We get “TRUE”. So theoretically encryption is enabled.
Then:
Why can we run SQL statements against server A from server B (with SSMS) without any certificate?
Are we wrong when we expect server A to refuse any client that do not have the right certificate?
How can server B, without any certificate, decrypt the data encrypted by server A?
Our intention is to encrypt all server in the same way so all of them will accept only encrypted communications. We are assuming that the Merge Agent will be able to communicate with the Publisher and the Subscriber through this encrypted environment. May
anyone please confirm ti?
Thanks for your help.
Best Regards
Benjamin Moles -
hi to all,
I am trying to write use inner joining . here is code
DATA:tabname LIKE dd02L-tabname,
table_disc LIKE dd02t-ddtext.
SELECT dd02ltabname dd02tddtext INTO (tabname,table_disc)
FROM dd02l INNER JOIN dd02t on dd02ltabname = dd02ttabname
WHERE dd02tddlanguage = 'E' AND dd02ltabclass = 'TRANSP'
AND dd02L~tabname = 'ZANKI*'.
endselect.
write : tabname.
I also checked in tables dd02t and dd02l for the table zanki* and data available in both table . but here select statement not working .do u have any idea about this. thank youHi,
I executed the ur inner join conditin by commenting 'z*' it's working fine.
I think where condition is not getting satisfied so u r not getting any data.
Please conform in where condition you need * 'AND'* or OR
I change decalration as below.
DATA:tabname type TABNAME,
table_disc type AS4TEXT.
SELECT dd02l~tabname
dd02t~ddtext INTO (tabname, table_disc)
FROM dd02l INNER JOIN dd02t on dd02l~tabname = dd02t~tabname
WHERE dd02t~ddlanguage = 'E' AND
dd02l~tabclass = 'TRANSP'AND
dd02L~tabname = 'ZANKI*'.
endselect.
write : tabname.
Regards,
Pravin -
I am using the sender jdbc sender adapter.
I had given the SQL Query:
EXECUTE xyz;
i am getting SQL Exception.
SQL Statement not allowed in adapter monitoring.
GauravHi,
Which database you are using ?
Are you executing the Stored Procedure ?
check out this for the syntax etc-
http://help.sap.com/saphelp_nw2004s/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/content.htm
Regards,
Moorthy -
Sql is not working after changing from MsAccess into sql server
Following Sql is not working after changing from MsAccess into sql server.
sum(trn.sales) as sales,
sum(trn.cost) as cost,
sales - cost as profit // Here is not working . can we not use sales a column. Please advise
from trn
Kind Regards
pol
polachanIt will not work if use two different column from the table or column from two different table
Example
sum(trn.sales * trn.rate) as salesAmount,
sum(trn.cost) as cost,
sum(trn.salesAmount)-sum(trn.cost) as profit ----- Here is not working . can we not use sales a column. Please advise
from trn
Regards
polachan -
I hooked up new iMac to wireless network and now iPad and iPhone do not work using wireless. They did before hooking up the iMac. I am using a Netgear N300 router. Also my Netgear ethernet/homeplug for wireless TV internet no longer works. Any ideas? I have tried unplugging, restarting, and resetting. No luck! Thanks!
You should probalby contact Netgear
-
What will you do if any SQL is not working. in oracle 10g....apps 11.5.10.2
928714 wrote:
yes sir.If you help me in answering my questions i wll be very thankful to you sir.
tnx,I haven't a clue.
As you have been advised in many of your posts, go study the documentation for whichever specific topic you are interested in.
For me to answer your questions, I would need to go get that documentation.
Then I would need to read that documentation.
Then I would need to write a forum post that interprets what I think I learned from that documentation.
It is so very much faster if YOU go do that instead of posting to a forum and expecting others to do it. You will remember what you study for a lot longer time if you teach yourself. -
Using export slide show from iphoto, I am trying to create a DVD of photos and vid clips in large format. The vid clips do not work using burn software. Any idea?
Have used large format, but using the 'burn' software, I am not getting seamless video quality on DVD even though I am burning at 2* speed. Any ideas? Do I need better software? Or is there a problem with the SuperDrive?
-
when i finally connected my mac to work network on windows environment everything related to apple including App store, Safari, software updates, iCloud and iTunes do not work using a proxy server and everything else is working very well including chrome browser…i tried everything but no clue...anybody have solution for this..???
I also forgot to note that this problem also persists with the new iBooks application. I cannot get past the 'Get Started' screen or access the iBooks Store. Again, all top bar menus are unresponsive.
DT -
SQL STATEMENT NOT PROPERLY ENDED - HELP NEEDED
Can anyone tell me the error in this code, I get an error message sql statement not properly ended when I run it.
update MODT set rootobj=(SELECT REF(A) FROM
OR_COMP_T A
WHERE A.ID=O.ID)
AS OR_COMP_T_REF)
FROM OLD_MODT O where id = 1;Hi, here is the schema and the expected results.
=======================================================================================
CREATE TYPE OR_MODT_OBJ;
CREATE TYPE OR_MODT_OBJ_REF AS TABLE OF REF OR_MODT_OBJ;
=================================================
CREATE OR REPLACE TYPE OR_COMP_T_OBJ
(id number (6),
typ char (4),
SUPERID REF OR_COMP_T_OBJ,
MOD REF OR_MODT_OBJ);
=================================================
CREATE OR REPLACE TYPE OR_COMP_T_REF AS TABLE OF REF OR_COMP_T_OBJ;
=================================================
CREATE TABLE OR_COMP_T OF OR_COMP_T_OBJ
=================================================
CREATE TYPE OR_MODT_OBJ
(id number (6),
typ char (4),
rootobj REF OR_COMP_T_OBJ,
comp_tb OR_COMP_T_REF);
=================================================
CREATE TABLE MODT OF OR_MODT_OBJ
NESTED COMP_TB STORE AS COMP_TB_NESTED;
=================================================
INSERT INTO OR_MODT (ID,TYP,ROOTOBJ,COMP_TB)
SELECT ID,TYP,NULL,NULL FROM OLD_MODT;
INSERT INTO OR_COMP_T(ID,TYP,SUPERID,MOD)
SELECT ID,TYP,NULL,NULL FROM OLD_OR_COMP_T;
==================================================
There are two rows in OLD_MODT, and these two rows are to be inserted into OR_MODT.
They are:
Sample data in OLD_MODT are:
id, typ, rootobj
1 type1 1
2 type3 365
=================================================
Data from OLD_OR_COMP_T is to be inserted into OR_COMP_T as well, and likewise, it has a ref to OR_MODT, so the ref data was not inserted at the same time.
Now OLD_OR_COMP_T has a number of rows but attribute MOD for two of these rows os the rootobj for OR_MODT,
such that:
id typ superID mod
1 type4 NULL 1
2 type2 10101 1
3 type 20202 1
365 type2 NULL 2
366 type2 20202 2
I want to get the ID of OR_COMP_T where ID is 1 and where ID is 365. These values are to be in rootobj.
I also want to get the value of ID in OR_MODT to be placed in MOD of OR_COMP_T.
PLEASE HELP ME.
Maybe you are looking for
-
Error message when I try to update phone
I havent updated my iphone since 2011 as I cant get passed an error message 1403. It says my iphone is corrupt. I have updated Itunes so many times and run diagnostics. I have backed up my phone and tried to restore but it says it is corrupt and can
-
Can someone provide direction on sharing an Apple ID for Itunes, but creating a separate Apple ID for Icloud?
-
How can I connect to other bluetooth devices
Hi Folks, Having only just become a new iphone 4s user I've now found out that my iphone will not connect to any other manufactured phones and other Bluetooth devices, is there any way around this or is it an iphone only club!!!. Many thanks in antic
-
Find space between word with different endings and digit
Hi, I'm trying to figure out how to find spaces between word and digit. I am limited to use only word 'WORD' (either capital or small caps) with different endings like -ing -s -y and more (using \S+). I wrote something like (?i)(?<=WORD\S+)\s(?=\d+)
-
hi All, Pls give me the details that how to use system defined smart forms and how to copy and change standard smart forms in SAP 4.7EE Thanks, Nitin