Convert script from Postgre to Oracle - timesten

I have a query in postgre, i convert it to oracle but it's can not run
update APITT_tbl_in set status ='Processing' where
id = (select id from APITT_tbl_in where upper(status)='PENDING'
and ROWNUM <= 1 order by priority, id FOR update)
returning reqid,command_name,api,request_msg,receive_node,command_type,id,sla,time_out,priority,receive_time
Below is error
TT1001: Syntax error in SQL statement before or at: ""
Error at Line: 4 Column: 108
I know that this error is can not use FOR UPDATE in subquery, but i can not repair it :(

Related

Getting below error while doing scd2 in snowflake using merge statement

My statement:
insert into target_scd2
select id,name,flag from (
merge into target_scd2 as t
using source as s
on t.id=s.id
when matched and t.name <> s.name then
update set flag='N'
when not matched then
insert values(s.id,s.name,'Y')
OUTPUT $Action action_flag,s.id,s.name,'Y'
) as merge_out
where merge_out.action_flag='UPDATE';
I am getting below error while executed the above statement:
SQL compilation error: syntax error line 3 at position 0 unexpected 'merge'. syntax error line 9 at position 29 unexpected ')'.
Can you please help what can be the issue
The pattern presented here is called: "INSERT over DML" and it is SQL Server specific.
More info: D. Inserting the results of the MERGE statement into another table
Can you please help what can be the issue
a) Using merge as subquery of INSERT SELECT
b) OUTPUT/(RETURNING) clause support
The Snowflake documentation of MERGE.

My stored procedure in SQL Server 2008 when is execute with JOB its fails, but without its working great

I have this stored procedure wich its like this :
ALTER PROCEDURE [dbo].[P_ALIMENTATION_VolumeVentes]
AS
BEGIN
SELECT EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS, SecteurNomEDS,DirectionEDS,DirectionNomEDS,
(SELECT count(*) FROM CPListeVentesNonConformes WHERE CPListeVentesNonConformes.EDS = CPRT.EDS AND TypePart='PP') AS ListeVenteNC_PP,
(SELECT count(*) FROM CEListeVentesNonConformes WHERE CEListeVentesNonConformes.EDS = CPRT.EDS AND TypePart='ET') AS ListeVenteNC_ET,
(SELECT count(*) FROM CPListeVentesNonConformes WHERE CPListeVentesNonConformes.EDS = CPRT.EDS AND TypePart='PP' OR TypePart='ET') AS ListeVenteNC_PPET,
(SELECT count(*) FROM ListeVentes WHERE IDES01 = CPRT.EDS AND TypePart='PP') AS ListeVentes
INTO VolumeVentes
FROM CPR CPRT
GROUP BY EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS, SecteurNomEDS,DirectionEDS,DirectionNomEDS,TypePart
END
When i execute with the command line EXEC [dbo].[P_ALIMENTATION_VolumeVentes]
that work super great my table is create.
But when i use SQL Agent to schedule a job i have a nice surprise to have this error :
Executed as user: ZRES\CSAPREP10IUCRADM. The conversion of a varchar
data type to a datetime data type resulted in an out-of-range value.
[SQLSTATE 22007] (Error 242) The statement has been terminated.
[SQLSTATE 01000] (Error 3621). The step failed.
The structure table who will be create VolumetVentes have no fields with a type as datetime
Here is the structure of the tableVolumeVentes
I don't understand exactly where is the error ?
Thank you for help
Actually it should never work since you already have VolumeVente table.
SELECT INTO creates new table with columns described in select statement
https://msdn.microsoft.com/en-us/library/ms188029(v=sql.120).aspx
You should modify this code to become INSERT SELECT.
But you will probably still get the same conversion error because (I guess) column order is not correct in select statment and does not match column order in existing table. That is why you should always explicitly define column list in INSERT INTO clause, so the final script will look like:
INSERT INTO VolumeVentes(EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS, ...)
SELECT EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS
FROM ...
Use
INSERT INTO... Statement
instead of
SELECT INTO FROM... Statement

If-Else condition in H2 database query

I have a connector application which reads from third-party database using apache camel. I am trying to mock the same database and query operations using H2 database, so that connectivity to the thirdparty database is not required for testing.
The database is in MS SQL Server. I am using the Mode as SQLServer in my H2 database. However, I have a mssql query with if-else condition. When I try to execute it, I am getting the following error.
MSSQL query is
if((SELECT count(*) from Employee where DateCreated < '2016-02-02 00:05:00')>1)
SELECT TOP 10 * from Employee where DateCreated < '2016-02-02 00:05:00'
else
SELECT TOP 1 * from Employee where DateCreated < '2016-02-02 00:05:00'
Error Message :
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement " IF[*]((SELECT COUNT(*) FROM EMPLOYEE)>1)
SELECT TOP 10 * FROM EMPLOYEE
ELSE
SELECT TOP 1 * FROM EMPLOYEE "; expected "INSERT, {"; SQL statement:
if((SELECT count(*) from Employee)>1)
SELECT TOP 10 * from Employee
else
SELECT TOP 1 * from Employee [42001-185]
I am assuming that the conditional query is not supported in the H2 database. IS there anyway, I can execute this same query in H2?
Worst Case, is there any otherway, in which I can change the mssql query which is compatible with H2 ?
I don't think there is. You can use the case command in H2 for the if/else effect, and in your application could factor the code that goes into the conditions and/or statements to execute so that you write it and use it in both your ms sql and h2 requests.

SSIS 2010 update table with decimal data type gives error "type not supported.DBTYPE_DECIMAL"

Strange error, Using SSIS 2010 on 2012 Enterprise Edition db.
Using OLEDB connection.
Variable a,b,c are defined as Decimal in ssis.
d is defined as a String.
Sql Task:
Select min(col1),max(col1) from table_a
where key_value = ?
where: parameter 0 is d , data type=Varchar
resultset 1 is a , 2 is b
Expression task:
#[User:c] = (DT_DECIMAL,2) (#[User:a] + #[User:b])
Sql Task:
Update table_a
set col2 = ?
where key_value = ?
where: parameter 0 is c (DataType=DECIMAL) and 1 is d (DataType=Varchar)
Error: ... failed with the following error: "The type is not
supported.DBTYPE_DECIMAL". Possible failure reasons: Problems with
the query, "ResultSet" property not set correctly, parameters not
set correctly, or connection not established correctly.
table_a is defined as
d varchar(4),
col1 numeric(10,2),
col2 numeric(10,2)
There are multiple rows of d and no index on table...
I've tried casting and converting the value in the update statement
Any ideas what's in error ?
Thanks
Check the parameter mapping section of your SQL task(s) to ensure the parameters are set properly.
I've seen this before, 'parameter not set correctly' is the key.

SSIS list rows that do not update

I am using an OLE DB Command to update records in a table. I want to seperate rows that update successfully from rows that do not update (different than error). Some rows will not update because the key I am updating does not exist. This is different than an error, because the command ran so I can not use the red error line. The only idea I have would be the equivalent to when I execute the update in SQL Server and it says "(0 row(s) affected)" and I would be able to do a comparison.
Since this does not count as an error in SSIS, I can't use the red error line. Does anyone know how to catch records that do not update?
catch it in a table
Select *
INTO Some_table
FROM Table_you_are_updating_From as a
WHEre NOT EXISTS(Select *
FROM Table_you_are_updating as b WHERE a.key=b.key )

Resources