Converting Oracle query to Sql Server with date manipulation

The following SSIS statement works great in Oracle, and it parses successfully in the "Sql Task" window. In Oracle it returns
this result:
FROM_DT              THRU_DT
16-Jan-2014      23-Jan-2014
select
case
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then to_date('24'||to_char(add_months(sysdate,-1),'mmyyyy'),'ddmmyyyy')
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('01'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('08'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
else to_date('16'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
end as from_dt,
case
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then trunc(last_day(add_months(sysdate,-1)))
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('07'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('15'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
else to_date('23'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
end as thru_dt
from sys.dual
How can I convert this to Sql Server ?

>>You mean you get the data from Oracle and tries to insert it into SQL Server?
- no, sorry, I want to convert the syntax to Sql Server
>>Are
you running the query in OLEDB provider connected to the Oracle's database?
- yes, this works fine now (after fixing this redundancy:
to_char(to_date(sysdate,'dd-mon-yyyy'),'dd')change toto_char(sysdate,'dd')

Similar Messages

  • Converting MDX query into SQL Server 2008

    We have MDX query based OLAP CUbes.
    To reduce MDX based dependenies, we have to convert MDX based cube to sql server 2008 based queries.
    For this I need expert advise to convert below query to sql server 2008 based query :
    CREATE MEMBER CURRENTCUBE.Measures.[Ack Lost]
                        AS 'Sum(PeriodsToDate([Time].[Year], [Time].CurrentMember ), [Measures].[Lost])',
                        FORMAT_STRING = "#,#",
                        VISIBLE = 1;

    Hi Sachin,
    According to your description, you need to convert the MDX query to T-SQL query, right?
    Your MDX query is calculated measure that return the total value from the first sibling and ending with the given member. In T-SQL query we can use the query as Yogisha provided to achieve the same requirement. Now you need to a tool to convert all the MDX
    related SSAS cube queries to MS SQL Server 2008 based queries.
    Although MDX has some similarities with T-SQL these languages are in many ways different. Beginning to learn and comprehend SQL Server Analysis Services (SSAS) MDX queries can be difficult after one has spent years writing queries in T-SQL. Currently, there
    is no such a tool to convert a MDX query to T-SQL query since the structure difference between MDX and T-SQL. So you need to convert them manually, please refer to the links below to see the details.
    http://www.mssqltips.com/sqlservertip/2916/comparison-of-queries-written-in-tsql-and-sql-server-mdx/
    https://sqlmate.wordpress.com/2013/11/12/t-sql-vs-mdx-2/
    http://technet.microsoft.com/en-us/library/aa216779(v=sql.80).aspx
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to convert Oracle database to Sql server Database

    Hi All,
    I have one database made in the Oracle 8i, i want to convert that database to Sql Server Database,
    Can anyone please give me the step by step process to do this conversion.
    Regards
    Ramesh Jha

    Try using the DTS (data transformation services) services of SQL Server 2000
    DTS is based on an OLE DB architecture that allows you to copy and transform data from a variety of data sources. For example: Oracle directly, using native OLE DB providers.
    Alternatively, you could follow the following broad steps for data migration (assuming you are retaining the same table structures in SQL Server, and that you are talking about SQL Server 2000).
    1. Get the CREATE scripts corresponding to each Oracle table / view / index. These can be reverse engineered from the database using a tool.
    2. Map Oracle datatypes to SQL server datatypes e.g: date maps to datetime/smalldatetime, numeric maps to one of int, bigint, smallint, etc depending on the range of values in the CREATE scripts.
    3. Indexes in SQL Server are of two types: Clustered / non-clustered. There can only be one clustered index on each table.
    4. Converting procedures and triggers will have to be line by line, since SQL Server uses a proprietary T-SQL instead of ORacle's PL/SQL
    I have yet to see a really good tool to do this migration, but it is possible to write a PL/SQL procedure / Pro*C program to automate the script creation for creating tables in the SQL Server database.
    For the actual data import into SQL Server, export the Oracle data table by table into flat files, and then use the import wizard of SQL Server enterprise manager

  • Why can't i use "INNER JOIN" in a query for SQL Server with JDBC??????

    Hi,
    I'm trying to execute some SQL queries and I just don't understand what's wrong.
    I�m using Tomcat and SQL Server in order to do this, but when I�m try to execute a query with a INNER JOIN statements Tomcat raise a SQL exception... at the very first time I thought there was a problem with database connection but I realize that a simple query to a table works pretty well. then I found out some problems with JDBC:ODBC.... so I install JDBC for SQL Server 2000 and test with the same simple query and works..... so, I come to a conclusion.... INNER JOIN or JOIN statements can't be used in JDBC..... please... somebody tell I�m wrong and give me a hand...
    I'm using TOMCAT 4 and JDK 1.4 SQL Server 2000
    Error occurs when executeQuery() is called.... not prepareStatement().... ??????
    Driver DriverRecResult = (Driver)Class.forName(driver).newInstance();
    Connection ConnRecResult = DriverManager.getConnection(DSN,user,password);
    PreparedStatement StatementRecResult = ConnRecResult.prepareStatement(query);
    ResultSet RecResult = StatementRecResult.executeQuery(); <---- Exception raise here
    So much tahnks in advance,

    That's exactly what I think, driver it's raising the exception, but I don't know why.... i test the same query with INNER JOIN directly from SQL Query Analyser and it's works perfectly, my problem ain't SQL, but JSP and JDBC 'cause i'm a newbie about these issues.
    Common sense tell me possible problems lie in SQLServer drivers 'cause i run the same pages on JRUN through jdbc:odbc and do works well, but by now i just depend on Tomcat.....
    I've installed SQL Server drivers for JDBC but i just find it doesn't work fully... could be the version of JDK i've installed? what version do i need?
    ( I'm running Tomcat 4 with JDK 1.4 & SQL Server 2000 W2K )
    thanks for reply.

  • Oracle 11G Direct SQL Load with Data Guard

    Does SQL Loader in direct mode always bypass the writing of redo logs ?
    If the database has force logging on, will SQL Loader in direct mode bypass the writing of redo logs ?
    Is there a way to run SQL Loader in direct mode that will create redo logs that can be applied by Data Guard to the backup database ?

    846797 wrote:
    Does SQL Loader in direct mode always bypass the writing of redo logs ?
    If the database has force logging on, will SQL Loader in direct mode bypass the writing of redo logs ?
    Is there a way to run SQL Loader in direct mode that will create redo logs that can be applied by Data Guard to the backup database ?In case of data guard setup , redo logs will always be generated.

  • Convert MS SQL server image data type into oracle clob

    Hi all! I'm tryng to access to Microsoft SQL server with Oracle via ODBC. Oracle is not able to use the image data type of Microsoft SQL server. Do you know a way to convert this data type in an oracle format? The explicit casting converts image to long raw, but after the conversion Oracle is not able to manage these data type. Thank you very much!
    Stefano.

    Hi you might want to post your question in General Forum.
    General Database Discussions
    There's very few users visit this forum.

  • Help with translating SQL query from SQL Server syntax to Oracle syntax

    Hi,
    is it someone that can help me translate following SQL query from SQL Server syntax to Oracle syntax.
    SELECT ID,
    [LMT(MTR)] = MAX(case when TYPE = 'LMT' then VALUE end),
    [AAD(KGM)] = MAX(case when TYPE = 'AAD' then VALUE end),
    [VOL(MTQ)] = MAX(case when TYPE = 'VOL' then VALUE end)
    FROM yourtable
    GROUP BY ID
    Your help is highly appreciated, thanks in advance.

    Like this,
    SELECT ID,
    MAX(case when TYPE = 'LMT' then VALUE end) LMT_MTR,
    MAX(case when TYPE = 'AAD' then VALUE end) AAD_KGM ,
    MAX(case when TYPE = 'VOL' then VALUE end) VOL_MTQ
    FROM yourtable
    GROUP BY ID-Arun

  • Insert data into oracle based on sql server data(here sql server acting as source to oracle and destination to oracle)

    Source is Oralce. Destination is SQL Server.
    Requirement - I have to fetch sql server server data (empid's) based emp table  and send this as input data to oracle to fetch and empid's are common.
    I cannot use merge or loopkup or for each as oracle have too many records.
    For example - In MS SQL - i have empid=1,2..Only these records, I have to fetch from oracle source into sql server destination. For this, I have adopted the below approaches...The major problem I face, when i build a empid's as a string, it is taking only
    4000 chars. My string lenght is 10000. How do I breakup this string lengh and send to data flow task till all broken strings length passed to DFT.
    Approach-1
    created two variables - oraquery string, empid string
    step1 - ms sql database - created sql task - declare @empid varchar(max)
    SELECT @empid=
    Stuff((SELECT ',' + empid
            FROM  
            (SELECT  DISTINCT  convert(varchar(10),empid ) empid FROM emp
             ) x
            For XML PATH ('')),1,1,'')
    select @empid =    '(' +  @empid + ')'
    select @empid
    resultset=singlerow
    resultset=resultname=0; variablename=User::empid (empid is declared as string)
    step2 - oracle database - created data flow task
    created oledb source
    I put  this statemnt in oraquery expression - "select * from dept where dept in  "
    +  @[User::empid] + "
    expression=true
    [OLE DB Source [1]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E14.
    An OLE DB record is available.  Source: "Microsoft OLE DB Provider for Oracle"  Hresult: 0x80040E14  Description: "ORA-00936: missing expression".
    Approach-2
    created three variables - oraquery string, empid  int, loop object--when I put int then it is automatically setting to 0
    step1 - ms sql database - created sql task - SELECT  DISTINCT  convert(varchar(10),empid ) empid FROM emp
    resultset=fullresult
    resultset=resultname=0; variablename=User::loop
    step2 - created a for each loop container
    for loop editor - for each ado ennumerator
    enumerator configuration - loop
    variablemapping - variable=empid;index=0
    step3 - oracle database - created data flow task (outside for each loop. If I put inside it is taking long time)
    created oledb source
    I put  this statemnt in oraquery expression - "select * from dept where dept in  "
    +  @[User::empid] + "
    expression=true
    Data inserting in a destination table but  empid=0.

    Sorry didnt understand if your step3 is outside loop how
    @[User::empid] will get values for the empids from User::loop. The iteration happens inside loop so you
    need to have a logic to form the delimited list inside using a script task or something and concatenating everything and storing to variable @[User::empid]
    . Then only it will have full value used to be used in step3 query
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Import Oracle DataBase dump file Into Sql Server With out connection oracle using c# code.

    Hi All,
    I would like to ask how can imports my dump oracle database file data and struct into sql server 2005
    with out make connection oracle.
    best regards.
    Hakim. 

    Hi Hakim.
    Based on your title, what I understood there is a issue regarding transfer oracle db dump to sql database using C# code. Am I right? If so, I am afraid there is no build-in method which meet your requrements in .NET framework. You must provides
    OraDump  Export API to allow developers integrate corresponding capabilities  into their applications. These capabilities are about export data from  Oracle dump files into popular databases like Microsoft SQL server. Every developer
    having OraDump Export API can write just few lines of code on C# or  Visual Basic to implement the appropriate export process.
    I am search a third-party link, but it's a paid service. 
    http://www.convert-in.com/data-migration-service.htm
    If you don't have to with code, Please refer to: Migrating Oracle Databases to SQL Server 2000
    http://technet.microsoft.com/en-us/library/cc966513.aspx
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Different output of same query in SQL Server and Oracle

    I have two tables table1 and table2
    --table1 has two columns c1 int and c2 varchar. there are not constraints added in it. it has data as given below
    c1     c2
    6     d
    5     j
    102     g
    4     g
    103     f
    3     h
    501     j
    1     g
    601     n
    2     m
    --table2 has only one column c1 int. there are not constraints added in it. it has data as given below
    c1
    6
    1
    4
    3
    2
    now when i run below given query in sql server and oracle it gives me different result
    select *
    from table1
         inner join (SELECT ROW_NUMBER() OVER (order by c1 ASC) AS c1 from table2) table2 on table2.c1=table1.c1
    sql server output
    c1     c2     c1
    1     g     1
    2     m     2
    3     h     3
    4     g     4
    5     j     5
    oracle output
    C1 C2 C1
    5 j 5
    4 g 4
    3 h 3
    1 g 1
    2 m 2
    If you notice the first column in both output. It is sorted in sql server and not in oracle.
    Why it is behaving differently in oracle? Is there any way I can solve this in oracle?
    Thanks,
    Jigs

    It is NOT behaving "differently" in Oracle; you just haven't specified an order that you expect your results to be in, so you're going to get output in whatever order the database fancies displaying it (ie. no guarenteed order). This is an artifact of how the database chooses to put together the data, and different databases (or even datasets within the same database) can and most likely will behave differently.
    Even SQL Server won't guarentee to always get your data in an ordered fashion if you exclude the order by clause, even if you think it has always output the data in an ordered fashion.
    Your solution is to add an order by clause, in BOTH databases, to force the order of the output data.

  • Writing a stored procedure to import SQL Server table data into a Oracle table

    Hello,
    As a new DBA I have been tasked with writing a stored procedure to import SQL Server table data into an Oracle table. I have been given many suggestions on how to do it from SQL Server but I I just need to write a stored procedure to run it from the Oracle side. Suggestions/guidance on where to start would be greatly appreciated! Thank you!
    I started to write it based on what I have but I know this is not correct :/
    # Here is the select statement for the data source in SQL Server...
    SELECT COMPANY
    ,CUSTOMER
    ,TRANS_TYPE
    ,INVOICE
    ,TRANS_DATE
    ,STATUS
    ,TRAN_AMT
    ,CREDIT_AMT
    ,APPLD_AMT
    ,ADJ_AMT
    ,TRANS_USER1
    ,PROCESS_LEVEL
    ,DESCRIPTION
    ,DUE_DATE
    ,OUR_DATE
    ,OUR_TIME
    ,PROCESS_FLAG
    ,ERROR_DESCRIPTION
      FROM data_source_table_name
    #It loads data into the table in Oracle....   
    Insert into oracle_destination_table_name (
    COMPANY,
    CUSTOMER,
    TRANS_TYPE,
    INVOICE,
    TRANS_DATE,
    STATUS,
    TRANS_AMT,
    CREDIT_AMT,
    APPLD_AMT,
    ADJ_AMT,
    TRANS_USER1,
    PROCESS_LEVEL,
    DESCRIPTION,
    DUE_DATE,
    OUR_DATE,
    OUR_TIME,
    PROCESS_FLAG,
    ERROR_DESCRIPTION)
    END;

    CREATE TABLE statements would have been better as MS-SQL and Oracle don't have the same data types.
    OUR_DATE, OUR_TIME will (most likely) be ONE column in Oracle.
    DATABASE LINK
    Personally, I'd just load the data over a database link:
    insert into oracle_destination_table_name ( <column list> )
    select ... <transform data here>
    from data_source_table@mssql_db_link
    As far as creating the database link from Oracle to MS-SQL ... that is for somebody else to answer.
    (most likely you'll need to use an ODBC driver)
    EXTERNAL TABLE
    If the data from MS-SQL is in a CSV file, just use and external table.
    same concept:
    insert into oracle_destination_table_name ( <column list> )
    select ... <transform data here>
    from data_source_external_table
    MK

  • What is the easiest way to export all tables data from Oracle to MS SQL Server?

    Hello MS,
    I would like to export all tables from Oracle 11.2 to MS SQL Server 2012 R1.
    Using the tool "Microsoft SQL Server Migration Assistant v6.0 for Oracle" did not work for me because there are too many warnings and errors regarding the schema creation (MS cannot know it because they are not the schema designer). My idea is
    to leave/skip the schema creation to the application designer/supplier and instead concentrate on the Oracle data export and MS SQL data import.
    What is the easiest way to export all tables data from Oracle to MS SQL Server quickly?
    Is it:
    - the „MS SQL Import and Export Data“ Tool
    - the “MS SQL Integration Services” Tool
    - not Oracle dump *.dmp format because it is a propritery binary format
    - flat file *.csv (delimited format)
    Thanks!

    Hi lingodingo,
    If you want to directly export all tables from Oracle database to SQL Server, I suggest you use SQL Server Import and Export Wizard. Because you just need to follow the wizard with GUI, this is the easiest way.
    If you want to make some modification for the tables‘ data before loading to SQL Server, I suggest you use SQL Server Integration Services package. For more details, please refer to the following similar thread:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/38b2bed2-9d4e-48d4-a33f-1d9eed1c062d/flat-file-to-sql-server?forum=sqldatamining
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How to migrate an existing Microsoft SSIS deployment if it is decided to replace SQL Server with an Oracle database?

    Hi Oracle Gurus!
    Currently, I am designing an ETL solution that transforms and loads a lot of data from flat files and sends it to an SQL Server 2008 R2 database for storage. However, at a future point of time, it may be decided to add or even replace SQL Server with an Oracle 11g database.
    Currently, I am writing script transforms in C# to dynamically generate SSIS packages to tansform and load the data into SQL Server. But considering that in future, an Oracle 11g or 12c database might be added to, or replace the SQL Server database, how do I make my script transforms (or whatever else I am developing currently for SQL Server) reusable to the extent possible?
    Or more precisely, what steps do I take, from an Oracle point of view, to ensure that any future migration of data to an Oracle database would be smooth to the extent possible?
    Looking up to my Oracle Gurus for enlightenment in this matter!
    Novice Kid

    When you're writing your on C# code to load data into the SQL Server you have to modify the routines so that they will work with Oracle.
    One approach is to use the extproc agent which would allow you to directly call external programs with all the logic in it to perform the load of your files and to put the data into the Oracle database. Another option would be to use utl_file package (or equivalents) which will allow you to open external files from your Oracle database and to directly read its content and then to pass it to the related tables.

  • I want to query oracle database from sql server can anyone tell steps 2 fo

    i want to query oracle database from sql server can anyone tell steps 2 followed
    i tried with linked servers but it is throwing errors can anyone hepl in this regard
    The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
    OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].

    First of all - you are in the wrong forum.
    Look either for the Database general or search for Transparant / Heterogenous Gateways.
    cu
    Andreas

  • I want to query oracle database from sql server can anyone tell steps 2 fol

    i want to query oracle database from sql server can anyone tell steps 2 followed
    i tried with linked servers but it is throwing errors can anyone hepl in this regard
    The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
    OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].

    First of all - you are in the wrong forum.
    Look either for the Database general or search for Transparant / Heterogenous Gateways.
    cu
    Andreas

Maybe you are looking for

  • Do not buy TC! It can not be repaired other than by apple!

    I was first off the mark with this, pre-ordered, got it, looked great. Then. Crash, crash and more crash. Can not get at it to even reformat it! It says the disk needs repair but there is no repair option! What the hey? So do they mean take it to app

  • Premiere Elements 11 - transition preview screen

    I have 64 bit Windows 7 computer with a HD7870 video card. I've installed the latest Quicktime update and checked both Adobe & Windows for the latest updates and installed where necessary. When attempting to preview a transition from the list of avai

  • File Location Characteristic Type

    Hi all, I have a scenario to use the File Location Characteristic Typein my module.I created one Characteric Type of File Location value and applied to Account Entity. I gave the char value as "http://download.oracle.com/docs/cd/E18733_01/pdf/E18365_

  • Change text based on value selection in dropdown

    Hi I have created a table Product Table with three columns Value,Description and Price. What i want on screen is that the 'Value' should be displayed as a dropdown on screen and when i select a particular value from dropdown the next two fields on UI

  • Photoshop Element 11 import picture file

    While editing pictures on Photoshop Element 11, I can only import and edit one picture AT A TIME, but I CAN NOT IMPORT my entire picture file for editing, why is that. I can drag and drop each picture to the field for editing, but NOT the ENTIRE PICT