Thinking Cap's On Please: How to create a range in PL/SQL similar to C++

Okay, I had to step on go "Whoa!"
Goal: to write a segment of code that will detect and identify a value in a range and then replace it by the following progress on the next element. In other words range A . . Z, and value is current set to D. I want to detect "D" and UPDATE it to "E". I saw an example of using DECODE as follows:
For example:
You could use the decode function in an SQL statement as follows:
SELECT supplier_name,
decode(supplier_id,     10000,     'IBM',
10001,     'Microsoft',
10002,     'Hewlett Packard',
'Gateway') result
FROM suppliers;But, you need to still have logic increment the value within the range to the next higher value. Okay, it can be done, but seems like it could be painful without a build in Oracle function. The code that I must adapt is shown below where the AGL-X, or PGL-X will need to be incremented to AGL-Y, or PGL-Y. It might be easier to just use decode and hard fix 26 values for each if.
declare
cursor c1 is
select * from alumni.amrexrt
where amrexrt_pidm = 2895;
cursor c2 is
select * from alumni.amrexrt
where amrexrt_pidm = 2895;
amrexrt_rec     alumni.amrexrt%rowtype;
r2              alumni.amrexrt%rowtype;
begin
    for amrexrt_rec in c1 loop
    if (amrexrt_rec.amrexrt_exrs_code = 'AGL') then
    update amrexrt
        set amrexrt_exrs_code = 'AGL-X'
        where amrexrt_pidm = 2895
        and amrexrt_exrs_code = 'AGL';
    elsif (amrexrt_rec.amrexrt_exrs_code = 'MGL') then
    update amrexrt
        set amrexrt_exrs_code = 'MGL-X'
        where amrexrt_pidm = 2895
        and amrexrt_exrs_code = 'MGL';
    elsif (amrexrt_rec.amrexrt_exrs_code = 'PGL') then
    update amrexrt
        set amrexrt_exrs_code = 'PGL-X'
        where amrexrt_pidm = 2895
        and amrexrt_exrs_code = 'PGL';
    end if;
    Insert into alumni.amrexrt
        amrexrt_pidm,
        amrexrt_exrs_code,
        amrexrt_ext_value,
        amrexrt_ext_score,
        amrexrt_ext_level,
        amrexrt_activity_date
    Values
        amrexrt_rec.amrexrt_pidm,
        amrexrt_rec.amrexrt_exrs_code,
        amrexrt_rec.amrexrt_ext_value,
        '754',                                 --amrexrt_rec.amrexrt_ext_score,
        amrexrt_rec.amrexrt_ext_level,
        amrexrt_rec.amrexrt_activity_date
    end loop;
    for r2 in C2 loop
    dbms_output.put_line('PIDM: ' || r2.amrexrt_pidm || 'EXRS_CODE: ' || r2.amrexrt_exrs_code);
    end loop;
    --Rollback;
  end;In C++, you are able to specify a range and write it so the compiler can detect the position within the range. I don't or think that PL/SQL does this in the same way. Any thoughts? I am dry out of ideas.
Edited by: Preston on May 3, 2011 12:05 PM

Hi,
Preston wrote:
Very, interesting! Is there another way to utilize the first two lines without an "EXEC"? The security filter sniffs for EXEC outside of production and disables our connections.I used a bind_variable, :letters_in_order, just to make maintenance easier. In this simple example, that string was used twice; in your real application, you may need to use it more times. By setting a bind variable, I guaranteed that, if you needed to change the definition of :letters_in_order, you would only have to change the code in one place. If you have to make the change in several places, there's a chance that you'll miss one of those places, and that kind of mistake can be hard to find and fix.
You don't have to use any kind of variable; you can hard-code the string literal 'KPCOFGS' everywhere I use the bind variable, for example:
...  || SUBSTR ( 'KPCOFGS'
                 , 1 + INSTR ( 'KPCOFGS' ... 
The rest of this message shows different ways to use variables:
(1) Bind Variable (but no EXEC)
(2) Substitution Variable
(3) Column
<h3>(1) Bind Variable (but no EXEC)</h3>
"EXEC stmt;" is equivalent to BEGIN stmt; END;/", so you can try:
{code}
BEGIN
     :letters_in_order := 'KPCOFGS';
END;
{code}
The main query would remain exactly as posted earlier, with :letters_in_order.
I don't see any point in blocking EXEC, but allowing this, and maybe your security mechanism doesn't allow it.
<h3>(2) Substitution Variable</h3>
You could try a substritution variable:
{code}
DEFINE letters_in_order = KPCOFGS
{code}
and, wherever I originally used :lettrs_on_order, use the substitution variable, inside single-quotes:
{code}
... || SUBSTR ( '&letters_in_order'
     , 1 + INSTR ( '&letters_in_order' ...
{code}
Substitution variables are a much bigger security threat than bind variables, but that doesn't mean your system won't allow them.
<h3>(3) Column</h3>
The most promising approach (but perhaps the least efficient) would be to derive a column called letters_in_order right in the query. Here's one way:
{code}
WITH     got_letters_in_order     AS
     SELECT     code          -- and whatever other columns you need
     ,     'KPCOFGS' AS letters_in_order
     FROM     t
--     WHERE     ...          -- if you need any filtering, put it here
SELECT code
,     SUBSTR ( code
     , 1
     , INSTR (code, '-')
|| SUBSTR ( letters_in_order
     , 1 + INSTR ( letters_in_order
               , SUBSTR ( code
                    , 1 + INSTR (code, '-')
                    , 1
     , 1
     )     AS new_code
FROM got_letters_in_order          -- *** CHANGED ***
{code}

Similar Messages

  • How to create conditional update trigger in sql server

    How to create conditional update trigger in sql server

    You cant create a conditional update trigger. Once you create an update trigger it will get called for every update action. However you could write logic inside it to make it do your activity based on your condition using IF condition statement
    Say for example if you've table with 6 columns and you want some logic to be implemented on update trigger only if col3 and col5 are participating in update operation you can write trigger like this
    CREATE TRIGGER Trg_TableName_Upd
    ON TableName
    FOR UPDATE
    AS
    BEGIN
    IF UPDATE(Col3) OR UPDATE (Col5)
    BEGIN
    ....your actual logic here
    END
    END
    UPDATE() function will check if column was involved in update operation and returns a boolean result
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to create Number Range

    Hi All Sap Experts
    Please tell me How to create Number Range
    I tried with the Transaction Code " SNRO "
    But Im getting The following error
    Dialog box title : " Buffering Methods ".
    Message in the Dialog box is :
       -Numbers may be lost!
       -Do not use for Financial accounting Documents!!
    ?. Do you want set this Buffering method?
    And another error is :
    Dialog box title : " Transport number range intervals "
    Message in the Dialog box is :
         The number range intervals are not included in automatic customizing changes.
         Transport all changes made within range interval maintenance must be  
         triggered manually.
         In the initial screen for range interval maintenance function
    <b>      Interval</b>              -->      <b>Transport</b>
         Please note the information that you get when transporting intervals.
    So please tell me the solution for this error.
    Thank you
    Basu
    Another is

    hi,
    Create number range object using OYSN.
    Then call the following function modules.
    FORM get_next_id CHANGING p_discrep.
      DATA: last_id LIKE zrecaudit-discrep,
            quant   LIKE inri-quantity,    "dummy
            code    LIKE inri-returncode.  "returncode
      CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'
           EXPORTING
                object           = 'ZRECAUDIT'
           EXCEPTIONS
                foreign_lock     = 1
                object_not_found = 2
                system_failure   = 3
                OTHERS           = 4.
      IF sy-subrc = 0.
        CALL FUNCTION 'NUMBER_GET_NEXT'
             EXPORTING
                  nr_range_nr             = '01'
                  object                  = 'ZRECAUDIT'
             IMPORTING
                  number                  = last_id
                  quantity                = quant
                  returncode              = code
             EXCEPTIONS
                  interval_not_found      = 1
                  number_range_not_intern = 2
                  object_not_found        = 3
                  quantity_is_0           = 4
                  quantity_is_not_1       = 5
                  interval_overflow       = 6
                  buffer_overflow         = 7
                  OTHERS                  = 8.
        CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
             EXPORTING
                  object           = 'ZRECAUDIT'
             EXCEPTIONS
                  object_not_found = 1
                  OTHERS           = 2.
      ENDIF.
    ENDFORM.                    " get_next_id
    <u><i><b>refer the links</b></i></u>
    http://www.sap-img.com/ge003.htm
    http://www.sap-basis-abap.com/sapmm009.htm
    http://www.erpgenie.com/abap/code/abap33.htm
    http://www.kabai.com/abaps/z26.htm
    Rgds
    Anversha

  • How to create user defined metrics for SQL Server target?

    The customer is not able to create a user defined metrics for SQL Server target.
    This is very important for him to use this product.
    He is asking how to create user defined metrics?
    I sent him Note 304952.1 How to Create a User-Defined SQL Metric in EM 10g Grid Control
    But it would work for an Oracle DB, but his target is SQL Server DB
    Not able to find the "User-Defined Metrics" link from Database home page.
    How to create user defined metrics for SQL Server target?

    http://download-uk.oracle.com/docs/cd/B14099_19/manage.1012/b16241/Monitoring.htm

  • How to create a linked server to SQL in Oracle?

    I am able to create a linked server to Oracle in SQL.. But I do not know the steps to create a linked server too SQL in Oracle.
    How to create a linked server to SQL in Oracle? After creating the linked server to SQL, I would like to create triggers in Oracle DB to insert records into SQL DB.

    There are 2 products in Oracle you can use to link to a MS SQl Server. The first one is for free and it is called Database Gateway for ODBC. With a suitable 3rd party ODBC driver you can connect to any foreign database. The second gateway is our commercial gateway and it is called Oracle Database Gateway for MS SQL Server. It is designed for MS SQl Server connections and more powerful then Dg4ODBC. It know how to map a lot of Oracle functions to SQL Server equivalents and you can also use it to directly call SQL Server procedures or functions. This dedicated SQL server gateway is also able to participate in distributed transactions.
    But again, this is a commercial gateway and you have to purchase a license for that second gateway, the Database Gateway for MS SQl Server.
    - Klaus

  • How to create cube and measure in sql?

    How to create cube and measure in sql?

    Cubes, measures and dimensions are created in the AW using the Java API for Analytic Workspaces or through XML documents that are processed by this API. SQL commands are not available for creating cubes, measures or OLAP dimensions.

  • How to create numkr range in pe03

    hello experts
    how to create number range in pe03 when already some others number range is saved whether to delete the others ra nge  or create a new one under others. even after creating under otherwise it is showing as error

    Hi,
    Pls correct it T.code.. Number ranges will create in PA04 T.Code. not in PE03. PE03 for features. In PE03 - NUMKR  feature- will assign the default number range- for trigger automatic no. while hiring ee's.
    See, if already some number ranges saved into one number range, you can split it with other number range like;
    01 - 000001 - 100000
    Like in your system it was saved like above.
    now you want to split the above no. range to below number range. I hope you are expecting following way.
    01- 000001 - 50000
    01- 500001- 100000
    Regards,
    Devi.

  • How to Create a Temporary Table with SQL Server

    I know you can create a temporary table in SQL Server 2000, but not quite sure how to do it in CFMX 7, i.e., does the SQL go inside a <CFQUERY dbtype="query"> tag?
    I'm pulling the main set of records from an Oracle server (1st data source), but it does not contain employee names, only employee IDs.  Since I need to show the employee name along with the Emp ID, I'm then pulling a list of "current" employee names from a SQL Server (2nd data source), which is the main database on our CF server.
    I've got a QofQ that works fine, except it only matches EmpIDs that exist in both result sets.  Employees who are no longer employed, don't match, and don't display.  Since I can't do a LEFT OUTER JOIN with a QofQ, what I need to do is get the records from the Oracle server into the SQL Server.  Preferably in a temporary table.
    I was hoping if I could get those Oracle records written to a temp table on the main SQL Server, in same database as the Employee Name table, I could then write a normal <CFQUERY> that uses a LEFT OUTER JOIN.
    I think I could probably write a Stored Procedure that would execute the SQL to create the temporary table, but am trying to avoid having to write the SP, and do it the simplest way.
    This query will be a program that can be run hundreds of times per day, with a form that allows users to select date ranges, locations, and other options.  That starts the queries, which creates the report.  So I just need the temp table to exist only until all the SQL has run, and the <CFOUTPUT> has generated a report.
    If the premise is right, I just need some help with the syntax for creating a SQL Server temp table, when you want to write records to it from an external data source.  I'm trying the following, but getting an error:
    <CFQUERY name="ITE_Temp" datasource="SkynetSQL">
    CREATE TABLE #MyTemp
    (   INSERT INTO #MyTemp
    ITE2.TrueFile char (7) NOT NULL,
    ITE2.CountOfEmployee int NULL,
    ITE2.DTL_SUBTOT decimal NULL,
    ITE2.EMPTYPE char (3) NULL,
    ITE2.ARPT_CD char (3) NULL
    </CFQUERY>
    So I actually created a permanent table on the SQL Server, and wrote the below SQL, which does work, and does write the records to table.  I can then write another CFQUERY with a LEFT OUTER JOIN, and get all the records, including those that don't have matching employee name:
    <CFQUERY datasource="SkynetSQL">
    <CFLOOP index="i" from="1" to = "#ITE2.RecordCount#">
    INSERT INTO ITE_Temp
       (FullFile,
       EmployeeCount,
       DTL_Amount,
       EmployeeType,
       station)
    VALUES  ('#ITE2.TrueFile[i]#',
       #ITE2.CountOfEmployee[i]#,
       #ITE2.DTL_SUBTOT[i]#,
       '#ITE2.EMPTYPE[i]#',
       '#ITE2.ARPT_CD[i]#')
    </CFLOOP>
    </CFQUERY>
    But, I hate to have to create a table and physically write to it.  For one, it seems slower, and doing it in temp would be in memory, and probably much faster, correct?  Is there some way to code the above, so that it does something similar, but in a TEMPORARY TABLE?   If I can figure out how to do this, I can pull data from multiple data sources and servers, and using SQL Server temp tables, work with the data as if it was all on the same SQL Server, and do some cool reports.
    Everything I've done for the past few years, has all been from data from a single source, whether SQL Server, or another server.  Now I need to start writing reports where data can come from 3 or 4 different servers, and be able to do joins (inner and outer).  Thanks for any advice/help.  Much appreciated.
    Gary

    While waiting to hear back, I was able to write the query results from an outside Oracle server, to a table on the local SQL Server, and do the LEFT OUTER JOIN required for the final query and report to work.  That was with this syntax:
    <CFQUERY name="AddTableRecords" datasource="MyTable">
    TRUNCATE TABLE ITE_Temp
    <CFOUTPUT query="ITE2">
    INSERT INTO ITE_Temp
    (FullFile,EmployeeCount,DTL_Amount,EmployeeType,station)
    VALUES
    ('#TrueFile#', #CountOfEmployee#, #DTL_SUBTOT#, '#EMPTYPE#', '#ARPT_CD#')
    </CFOUTPUT>
    </CFQUERY>
    However, I was not able to write to a temporary table AND read the results. I got the syntax to run to write the above results to a temporary table.  But when I tried to read and output the results from the temp table, I got an error.  Also, it wouldn't take the single "#" (local) only the global "##" table var, using this syntax.  Note that if I didn't have the DROP TABLE in the beginning, the 2nd time you run this query, you get an error telling you the table already exists.
    <CFQUERY name="ITE_Temp2" datasource="MyTable">
    DROP TABLE ##MyTemp2
    CREATE TABLE ##MyTemp2
    FullFile char (7) NOT NULL,
    EmployeeCount int NULL,
    DTL_Amount decimal NULL,
    EmployeeType char (3) NULL,
    station char (3) NULL
    <CFOUTPUT query="ITE2">
    INSERT INTO ##MyTemp2 VALUES
    '#ITE2.TrueFile#',
    #ITE2.CountOfEmployee#,
    #ITE2.DTL_SUBTOT#,
    '#ITE2.EMPTYPE#',
    '#ITE2.ARPT_CD#'
    </CFOUTPUT>
    </CFQUERY>
    So even though the above works, I could use some help in reading/writing the output.  I've tried several things similar to below, but they don't work.  It't telling me ITE_Temp2 does not exist.  It's not easy to find good examples of creating temporary tables in SQL Server.
    <CFQUERY name="QueryTest2" datasource="SkynetSQL">
    SELECT *
    FROM ITE_Temp2
    </CFQUERY>
    <CFOUTPUT query="ITE_Temp2">
    Output from Temp Table<br>
    <p>FullFile: #FullFile#, EmployeeCount: #EmployeeCount#</p>
    </CFOUTPUT>
    Thanks for any help/advice.
    Gary.

  • HOW TO CREATE WINDOWS AUTHENTICATION USER IN SQL SERVER AFTER INSTALLING SQL SERVER 2008

    I had an error while executing asp.net appcation from IIS as follows
    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
    Description:
    An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
    [SqlException (0x80131904): Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.]
    Can the above problem be solved by CREATING WINDOWS AUTHENTICATION LOGIN FOR
    'IIS APPPOOL\ASP.NET v4.0'  ?
    If yes, how to create the login?
    If no,what is the best possible solution?
    Please reply as soon as possible as i am unable to run my project which I had done in my lab,in my home system.

    Hi Praveen,
    To fix this issue, you need to change the Identity of your website's Application Pool to use the
    NetworkService account (or the less secure LocalSystem account).  By default, IIS7 seems to set the Application Pools Identity to 'ApplicationPoolIdentity' instead of NetworkService or LocalSystem.
    Here's a step-by-step guide for determining your websites Application Pool, then changing its Process Model Idenitty in IIS7:
    1.Open Internet Information Services (IIS) Manger.
    2.In the Connections sidebar, drill down into Default Web Site and click on your website.
    3.Now in the Actions sidebar (on right side), click on Advance Settings... In the popup box, under General you will see your Application Pool listed for your website (in my case the app pool is: ASP.NET V4.0).
    4.Click Cancel...  If you choose, you can change the Application Pool here, but for the sake of this example we just wanted to find out what the website's App Pool was.
    Then change the app pool's (Process Model) Identity to 'NetworkService', the steps are showed as below:
    1.Open Internet Information Services (IIS) Manger.
    2.In the Connections sidebar, click on Application Pools.
    3.Now right-click on theApplication Pool that your website is using (in this case my site is using the ASP.NET v4.0 application pool), and select Advanced Settings... from the menu.
    4.In the Advanced Settings pop-up box, locate the Process Model -> Identity section and click on the Application Pool Identity.
    5.In the Application Pool Identity pop-up box, change the Built-in account to NetworkService (or if you want LocalSystem), then click OK, and click OK again to save your Advanced Settings changes.
    Hope this helps.
    Best Regards,
    Peja
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • How to create Batch file to execute sql scripts

    Hi friends,  
          i want to create batch file to execute all my .sql scripts.
    I have all table ( all table scripts in single file ) ,Udds ( all udds in single file ) ,Stored procedures( separate file for each SPs ),Functions ( Separate file for each Functions ),Triggers and views scripts in .SQL file.   
    can anybody tell me how to create batch file for executing all these scripts in sql server ?.   
       while executing, it should ask Database name,server name, password. if these details are given then it should execute my all scripts in given database
    , if any error thrown then that error and procedure name alone have to move to separate log file..
    Please help me if this possible or any other easy way to do this..
    Thanks - Ravi

    Hi  Mate.
    can i save the below details in my batch file parmantly, so that i don't need to provide the details agains again in CMD while i execute this. Please help
    set /p SName=Server Name :
    set /p UName=User Name :
    set /p Pwd=Password :
    set /p DbName=Database Name
    If  i am providing the details before execution of this bat file it will throw error.

  • How to create a counter using Oracle SQL Developer?

    Is there any way to create a counter using Oracle SQL Developer to create the below scenario. Meaning it will recorded down the name of user and ID and time and the date they login.
    Library portal home statistics shows how many users (outside and within the campus) visit the library portal.
    Page Access statistics is recorded on an hourly basis. Users may select the statistics by
    yearly (statistics displayed by all months in the selected year)
    monthly (statistics displayed by all days in the selected month)
    daily (statistics displayed by all hours in the selected day)

    I'm giving here one basic post - hope this will solve your problem --
    SQL>
    SQL>
    SQL> create table audit_info
      2   (
      3     usr        varchar2(50),
      4     log_time   timestamp(6)
      5    );
    Table created.
    SQL>
    SQL>
    SQL>  create table err_log
      2     (
      3       log_cd      varchar2(20),
      4       log_desc    varchar2(500)
      5     );
    Table created.
    SQL>
    SQL>
    SQL>   create or replace procedure ins_err(errcd   in  varchar2,
      2                                        errnm   in  varchar2)
      3    is
      4      pragma autonomous_transaction;
      5    begin
      6      insert into err_log values(errcd,errnm);
      7      commit;
      8    end;
      9  /
    Procedure created.
    SQL>
    SQL>
    SQL>   create or replace procedure ins_aud(ud   in varchar2,
      2                                        unm  in varchar2)
      3    is
      4      pragma autonomous_transaction;
      5    begin
      6      insert into audit_info values(ud,unm);
      7      commit;
      8    exception
      9      when others then
    10        ins_err(sqlcode,sqlerrm);
    11    end;
    12  /
    Procedure created.
    SQL>
    SQL>
    SQL>
    SQL> create or replace trigger log_odsuser1
      2   after logon on odsuser1.schema
      3   begin
      4     ins_aud('ODSUSER1',sysdate);
      5   exception
      6     when others then
      7       ins_err(sqlcode,sqlerrm);
      8   end;
      9  /
    Trigger created.
    SQL>
    SQL*Plus: Release 9.2.0.1.0 - Production on Tue Jun 12 12:21:09 2007
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    SQL>
    SQL>
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL>
    SQL> select * from audit_info;
    USR
    LOG_TIME
    ODSUSER1
    12-JUN-07 12.00.00.00000000 AMHope this will solve your purpose.
    Regards.
    Satyaki De.

  • How to create sub views in Oracle SQL

    I am trying to write a select statement through TOAD that needs to build a view and then query from that view further in the same statement. I don't mean create a VIEW in the common sense of running a CREATE VIEW command, I mean creating one dynamically within an SQL statement. Here's what I mean - in DB2 sql I can write the following:
    WITH COUNT_NUM
    COUNT_ADS
    AS
    (SELECT
    COUNT(AD_ID)
    FROM AD
    WHERE CONTRACT_ID = '000234123'
    SELECT * FROM COUNT_NUM;
    Obviously this is a real simple example but you get the idea. Using this syntax you can create numerous sub-views to build data into your final select. My question is how to do this for Oracle. I have searched tons of help pages and sites but the only reference is to creating permanent views. I do not want to create temporary views either as I do not have adequate system permissions - I only want to create dynamic ones within my SQL.
    Thanks in advance for any help!

    In Oracle, the equivalent concept is known as an in-line view. The Oracle version of your statement is:
    SELECT *
    FROM (SELECT COUNT(AD_ID) count_ads
          FROM AD
          WHERE CONTRACT_ID = '000234123')Essentially, you can use an in-line view anywhere you would use a "real" view or a table, so the follwoing is also possible:
    SELECT a.contract_id, a.count_ads, b.count_pages
    FROM (SELECT contract_id,ad_id,COUNT(*) count_ads
          FROM ad
          GROUP BY contract_id,ad_id) ads,
         (SELECT ad_id,count(*) count_pages
          FROM ad_pages
          GROUP BY ad_id) ad_pages
    WHERE ads.ad_id = ad_pages.ad_idHTH
    John

  • How to create a Linked Server from SQL Server 2012 to Postgresql

    Hi, I am working on a third party application which is using Postgresql version 9 database and I am trying create a linked server in SQL Server 2012 using the below stored procedure.
    EXEC master.dbo.sp_addlinkedserver @server = N'LINKEDSERVERPOSTGRES', @srvproduct=N'PostgreSQL',
    @provider=N'MSDASQL', @provstr=N'Driver=PostgreSQL;uid=pguser;Server=pghost;database=pgdatabase;pwd=somepassword'
    Error: Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server.
    I have no clue if a jdbc provider exists in SQL Server to connect to Postgresql or what the right provider is? Could you please let me know if there's a workaround to achieve this.
    Thanks in advance............
    Ione

    See if this helps
    http://www.postgresonline.com/journal/archives/46-Setting-up-PostgreSQL-as-a-Linked-Server-in-Microsoft-SQL-Server-64-bit.html
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to create number ranges with "OK60" transaction or any other.

    Hello,
    I need to create a new number range to asigne to a document type , using transaction OK60 ( the error says this transaction).
    but I only can display with this transaction, and I would like to update.
    Is there any other transaction to do this , or is there any way to do this with this transaction OK60?
    Thank you very much.
    Kind regards
    Olga

    Hi,
    OK60 indeed is used for creating number ranges for FI/CO earmarked funds transactions. You should press on 'Pencil' button and create an interval. If for some reasons, you cannot do this via this transaction, try using SNRO transaction, with IRW_BELEG parameter. If this also fails, then apply to BASIS team to check your authorizations.
    Regards,
    Eli

  • How to create minute range

    Hi experts,
    I need to populate two column in order to get waiting time, then i need to create minute range as below:-
    i ) less than 30 minute
    ii) 30 minute - 60 minute
    iii) 60 minute - 90 minute
    iv) more than 90 minute
    select TO_CHAR(abs(vlh.SERVICING_DATETIME-vlh.ARRIVAL_DATETIME )* 1440,'99999999.99'),count(TO_CHAR(abs(vlh.SERVICING_DATETIME-vlh.ARRIVAL_DATETIME )* 1440,'99999999.99'))
    from visitlochis vlh
    where servicing_datetime is not null
    and arrival_datetime is not null
    AND servicing_datetime >= TO_DATE ('01/01/2009', 'dd/mm/yyyy')
    AND servicing_datetime <= TO_DATE ('10/01/2009', 'dd/mm/yyyy')
    and (TO_CHAR(abs(vlh.SERVICING_DATETIME-vlh.ARRIVAL_DATETIME )* 1440,'99999999.99'))>=60
    and (TO_CHAR(abs(vlh.SERVICING_DATETIME-vlh.ARRIVAL_DATETIME )* 1440,'99999999.99'))<=90
    group by TO_CHAR(abs(vlh.SERVICING_DATETIME-vlh.ARRIVAL_DATETIME )* 1440,'99999999.99')
    Any advise and guidance is needed..
    Thanks in advance

    Hi,
    Welcome to the forum!
    What is the prupose of the WHERE -clause conditions:
    and (TO_CHAR(abs(vlh.SERVICING_DATETIME-vlh.ARRIVAL_DATETIME )* 1440,'99999999.99'))>=60
    and (TO_CHAR(abs(vlh.SERVICING_DATETIME-vlh.ARRIVAL_DATETIME )* 1440,'99999999.99'))<=90? It looks like you're trying to only get waiting times between 60 and 90 minutes; but since you're comparing strings to numbers (the expressions to the left of the >= and <= operators are strings, but the expressions to the right are numbers) you might be getting something you didn't expect.
    If you want to assign one of the numbers 1, 2, 3 or 4 to each row, depending on its wait time, you could always use CASE, like this:
    CASE
        WHEN  vlh.SERVICING_DATETIME - vlh.ARRIVAL_DATETIME <  (1 / 48)  THEN 1  -- 1/48 day = 30 minutes
        WHEN  vlh.SERVICING_DATETIME - vlh.ARRIVAL_DATETIME <  (2 / 48)  THEN 2
        WHEN  vlh.SERVICING_DATETIME - vlh.ARRIVAL_DATETIME <  (3 / 48)  THEN 3
        WHEN  vlh.SERVICING_DATETIME - vlh.ARRIVAL_DATETIME >= (3 / 48)  THEN 4
    END     AS  wait_grpTo avoid computing the difference 4 times, you could do it once in a sub-query.
    In certain circumstances, you can do something a little shorter.
    For example, if servicing_datetime is never earlier than arrival_datetime, you can get the same results as above like this:
    1 + LEAST ( FLOOR ( ( vlh.SERVICING_DATETIME - vlh.ARRIVAL_DATETIME)
                / 48
              , 3
           )   AS wait_grp

Maybe you are looking for

  • Why work protect mode doesn't work for IAC's of SRM in EP?

    But when IAC's are called from ITS this works fine, displaying message about save data. any advance it is thankful!

  • Automator app that works with files behaves randomly

    I have a VERY simple automator application that just copies a file, renames it, copies it again, renames it again, and that's all. It's all done with standard automator steps. For some reason, it behaves randomly. Sometimes it does the right thing; s

  • Can't save bluetooth songs from Inbox on Nokia X6

    When I send a file from a phone or computer it goes straight to my inbox and the pictures and videos will save to my gallery but there is no option for me to save songs, yet it will let me set them as a ringtone. Any help please?

  • How to manage language list in oracle bi logon page?

    Hello All! Can any one explain in detail, how "Select a Language" drop-down list is populated? How to exclude all but two languages from the list in BI 10g? It is well documented how to add languages, but this seems not to work in reverse. That is, d

  • How to create instance object of Attachments2

    I am trying to add attachments to Activities i.e. contacts. I read in 2005, Attachments2 replaces Attachments. 1) Just want to to know how to attach documents to Activities using Attachments2. 2) Or How to create an instance for Attachments2? Many Th