How to call Microsoft SQL User defined function??

I am trying to call Miscrosoft SQL user defined function (not stored procedure) and experience problems. The function -- func_profile_history takes 3 inputs and returns resultSet.
Please let me know if there is any examples some where. All the examples I found are for stored procedure.
Thanks....
Siu
************ source *************
public Vector callSqlFunction(String eidTradcom, String idSku, String endDate, String idUserPost)
throws TradcomException, RemoteException
System.out.println("--------------in callSqlFunction--------------1");
Connection conn = null;
java.sql.CallableStatement cstmt = null;
ResultSet rs = null;
ForecastInfo info = null;
Vector v = new Vector();
try{
conn = TradcomUtils.getConnection();
String sql = "{call func_profile_history(?,?,?)}";
System.out.println("--------------in callSqlFunction--------sql="+sql);          
cstmt = conn.prepareCall(sql);
System.out.println("--------------in callSqlFunction-------2");                         
cstmt.setString(1, eidTradcom);
cstmt.setString(2, idSku);
cstmt.setString(3, endDate);
System.out.println("--------------in callSqlFunction-------3");                    
rs = cstmt.executeQuery();
System.out.println("--------------in callSqlFunction-------4");                    
while (rs.next()){
     info = new ForecastInfo ();
     info.setEidTradcom(rs.getString("eid_tradcom"));
     info.setIdSku(rs.getString("id_sku"));                    
     info.setQtOnHand(rs.getDouble("qt_on_hand"));                    
     info.setQtOnHold(rs.getDouble("qt_hold"));
     info.setQtNetOnHand(rs.getDouble("qt_net_on_hand"));
     info.setQtAlloc(rs.getDouble("qt_alloc"));
     info.setQtAvailUnalloc(rs.getDouble("qt_avail_unalloc"));     
     info.setQtPoShip(rs.getDouble("qt_po_ship"));
     info.setQtPoRcvd(rs.getDouble("qt_po_rcvd"));
     info.setQtTransit(rs.getDouble("qt_transit"));
     info.setQtAsn(rs.getDouble("qt_asn"));                    
     info.setQtPo(rs.getDouble("qt_po"));
     info.setQtPoBalance(rs.getDouble("qt_po_balance"));
     info.setQtSoShip(rs.getDouble("qt_so_ship"));     
     info.setQt4Cast(rs.getDouble("qt_4cast"));
     v.addElement(info);
System.out.println("--------------in callSqlFunction-------5");     
System.out.println("--------------in callSqlFunction-------v="+v);          
return v;
}catch(Exception ex){
System.out.println("Error in callSqlFunction:"+ ex.getMessage());
throw CachingManager.getTradcomException(ex, "Error in callSqlFunction");
}finally{
try{ if (cstmt != null) cstmt.close(); } catch(Exception ex){}
try{ if (conn != null) conn.close(); } catch(Exception ex){}
********************* error output ***************
********************* bef calling callSqlFunction
--------------in callSqlFunction--------------1
--------------in callSqlFunction--------sql={call func_profile_history(?,?,?)}
--------------in callSqlFunction-------2
--------------in callSqlFunction-------3
Error in callSqlFunction:The request for procedure 'func_profile_history' failed
because 'func_profile_history' is a function object. Severity 18, State 1, Proc
edure 'LAP_DUAL null', Line 4
ERROR=Error in callSqlFunction...The request for procedure 'func_profile_history
' failed because 'func_profile_history' is a function object. Severity 18, State
1, Procedure 'LAP_DUAL null', Line 4

well, I tried the preparedStatemnet and it worked. Case closed.

Similar Messages

  • Calling PL/SQL user defined functions from ODI Constraints

    Hi All,
    We are trying to call user defined PL/SQL functions from ODI. We are able to call them from ODI's User functions. But when we are trying to call them from ODI Constraints under Models, it is throwing an error 'ORA-00920 invalid relational operator'. Kindly let me know if anyone has faced the same issue and got the resolution for the same. Thanks in Advance.
    Regards,
    Abhishek Sharma

    Hi Ace,
    Thanks for the response, the same error was coming in operator also.
    I am able to call PL?SQL user defined functions from ODI Constraints. We have to first call ODI User functions from the ODI constraints as we cant call PL/SQL function (compiled in database) directly.
    From the ODI User functions, we can then call the PL/SQL functions.
    Please reach out to me if you need further details reg this.

  • SQL User Defined Functions for performing statistical calculations

    Hi!
       I hope you can help.  I just wasn’t sure where to go with this question, so I’m hoping you can at least point me in the right direction.
       I’m writing a SQL Server stored procedure that returns information for a facility-wide scorecard-type report.  The row and columns are going to be displayed in a SQL Server Reporting Services report. 
       Each row of information contains “Current Month” and “Previous Month” numbers and a variance column.  Some rows may compare percentages, others whole numbers, others ratios, depending on the metric they’re measuring.  For each row/metric the company has specified whether they want to see a t-test or a chi-squared statistical test to determine whether or not there was a statistically significant difference between the current month and the previous month. 
       My question is this:  Do you know where I can find a set of already-written user defined functions to perform statistical calculations beyond the basic ones provided in SQL Server 2005?  I’m not using Analysis Services, so what I’m looking for are real SQL User Defined Functions where I can just pass my data to the function and have it return the result within a stored procedure. 
       I’m aware that there may be some third-party statistical packages out there we could purchase, but that’s not what I’m looking for.   And I’m not able to do anything like call Excel’s analysis pack functions from within my stored procedure.   I’ve asked.   They won’t let me do that.   I just need to perform the calculation within the stored procedure and return the result.
       Any suggestions?  Is there a site where people are posting their SQL Server UDF’s to perform statistical functions?  Or are you perhaps aware of something like a free add-in for SQL that will add statistical functions to those available in SQL?   I just don’t want to have to write my own t-test function or my own chi-squared function if someone has already done it.
     Thanks for your help in advance!  Oh, and please let me know if this should have been posted in the TSQL forum instead.  I wasn't entirely sure.
    Karen Grube

    STATS_T_TEST_
    docs.oracle.com/cd/B19306_01/server.102/b14200/functions157.htm 
    STATS_T_TEST_ONE: A one-sample t-test
    STATS_T_TEST_PAIRED: A two-sample, paired t-test (also known as a crossed t-test)
    STATS_T_TEST_INDEP: A t-test of two independent groups with the same variance (pooled variances)
    STATS_T_TEST_INDEPU: A t-test of two independent groups with unequal variance (unpooled variances)

  • How do you create a user defined functions  UDF and passing a value like a ID to GEt a Value.

    How do you create a user defined functions UDF and passing a
    value like a ID to GEt a Value.
    using a query.
    are there example.
    Thanks

    tons of examples at cflib.org - good place to start, even
    though many
    udfs there are a bit outdated in their code...
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • Using a SQL user-defined function in Crystal Reports XI

    Post Author: JoannKarp
    CA Forum: Formula
    Is it possible to use a user defined function in SQL and use this in multiple Crystal reports?
    JoannKarp

    SELECT COALESCE(ufn_GetAddressByBusinessEntityIDandAddressTypeID(table1.BusinessEntityID,712),ufn_GetAddressByBusinessEntityIDandAddressTypeID(table1.BusinessEntityID,712)) AS Zipcode
      FROM table1
    Nope. This is two function calls. coalesce(a, b, c, ...) is just syntatic sugar for
       CASE WHEN a IS NOT NULL THEN a
            WHEN b IS NOT NULL THEN b
            WHEN c IS NOT NULL THEN c
       END
    But if you use isnull it's a different matter. (But isnull() permits two arguments.)
    Erland Sommarskog, SQL Server MVP, [email protected]

  • ? Regarding 'SQL user-defined function' execution performance ?

    Hi All,
    I have an user-defined function in SQL which am using in a SQL select statement and i found that the execution time taken by the user-defined function is 9-10 minutes as a result of which my whole query execution time is affected.
    How to i improvise the execution time. Should i do some sort of scheduling for executing the user-defined functions only. Am new to the database world. Your early response with a good suggestion would really be appreciated.
    Thanks in Advance.

    Try to read SQL tuning documents along with TkProf. Then only you will be able to detect the problem.
    There is no instant method by which you can solve this problem.
    But, you can get idea from this samples.
    Tuning:
    http://www.dba-oracle.com/art_sql_tune.htm
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:8764517459743
    Reading TkProf:
    http://www.dbspecialists.com/presentations/use_explain.html
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:920429344869
    Regards.
    Satyaki De.

  • How to use StreamTransformationException in user-defined function?

    Hi,
    I'm doing a DBLookup (using Java pgm in one of my Imported Java archives) for populating one of the fields in message mapping. If the DB connection fails, I want to terminate the mapping by throwing a StreamTransformationException from within a user-defined function.
    I require urgent help in this regard.
    Thanks in advance.
    Regards,
    Sridhar Rajan N

    Hi,
    I had the same problem. I failed to find the way how to throw a StreamTransformationException in my user-defined function. But I used another exception: NullPointerException. Yes, I know, this is not an elegant solution...
    Best regards,
    Andrzej Filusz

  • HOW TO CREATE A GLOBAL USER DEFINED FUNCTION

    Hi Expert,
    I'd like to know if there is a way to globalize a user defined function?
    I'd like to reuse a user defined function (e. g. DeleteLeadingCharacter) in several scenario/SWC instead of recreated it from scratch everytime - Is it possible?
    Thanks

    NO you cannot not reuse one UDF not even in other namespace even in the same namespace in diff Mapping programme.
    UDF is liminted to GraphicalMappingProgramme that you created you cannot reuse it in other MappingProgrammes.
    Like your MM =A has function <b>getMyName</b>
    you can use it in MM=A but if you want to use it in MM=B then u cannot.
    So its not possible in XI or PI.
    But it is possible in new release PI 7.1. That says you can write UDF and can reuse in any MM programme.
    Thanks
    Farooq.
    *Rewards Points if you find it useful*

  • How do I modify a user-defined function in SQL Plus

    I have created some functions in my database. Can anybody tell me how to modify/edit those functions?

    PS C:\> $Class2 = New-Object MyTest.Class1
    PS C:\> $Class2
    MyString Struct1Property Struct2Property
    MyTest.Struct1 MyTest.Class1+Struct2
    PS C:\> $Struct2 = New-Object MyTest.Class1+Struct2
    PS C:\> $Struct2.Property = "X"
    PS C:\> $Struct2
    Property
    X
    PS C:\> $Class2.Struct2Property = $Struct2
    PS C:\> $Class2.Struct2Property.Property
    XPS C:\> $Struct2.GetType()
    IsPublic IsSerial Name                                     BaseType                                                                    
    False    False    Struct2                                  System.ValueType                                                            
    Struct2 is a valuetype, (by value)
    The classes are by reference
    PS C:\> $Struct3 = $Class2.Struct2Property
    PS C:\> $Struct3
    Property
    X
    PS C:\> $Struct3.Property = "Y"
    PS C:\> $Class2.Struct2Property.Property
    X
    PS C:\> $Class2.MyString = "A"
    PS C:\> $Class3 = $Class2
    PS C:\> $Class3.MyString = "B"
    PS C:\> $Class2.MyString
    B

  • How to Call Smartform from User defined Transaction

    Hi All,
    my requirement is users enters the  data in the module pool program and clicks on the save and generate smartform button and the data is updates the database tables and  updated data should be printed on smartform
    Can anyone Please tell me How to link Smart Program with module pool program.
    Regards,
    Prasad.

    In smartforms , right click any window and create->flow logic->program lines, then the screen for program logic appears. In the left most corner there a icon named statement struct.
    Click the statement struct icon, it will show the screen for pattern, there give the function module name that you want to include in smartforms
    case okcode.
    when 'SAVE'.
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING FORMNAME = P_FORM "Your form name
    variant = ' '
    direct_call = ' '
    IMPORTING FM_NAME = FM_NAME
    EXCEPTIONS NO_FORM = 1
    NO_FUNCTION_MODULE = 2
    OTHERS = 3.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    EXIT.
    ENDIF.
    calling the generated function module
    CALL FUNCTION FM_NAME
    EXPORTING
    ARCHIVE_INDEX =
    ARCHIVE_INDEX_TAB =
    ARCHIVE_PARAMETERS =
    CONTROL_PARAMETERS = CPARAM
    OUTPUT_OPTIONS = OUTOP
    USER_SETTINGS = SPACE
    MAIL_APPL_OBJ =
    MAIL_RECIPIENT =
    MAIL_SENDER =
    IMPORTING
    JOB_OUTPUT_INFO = TAB_OTF_DATA
    DOCUMENT_OUTPUT_INFO =
    JOB_OUTPUT_OPTIONS =
    EXCEPTIONS
    FORMATTING_ERROR = 1
    INTERNAL_ERROR = 2
    SEND_ERROR = 3
    USER_CANCELED = 4
    OTHERS = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    endcase.
    endform.
    endcase.

  • USER DEFINED FUNCTIONS IN FORM 6i

    I am interested to learn how can I manipulate, call a database user define function in a form6i that I am now using. It should give me desire database information on the forms? I am sorry, if I could explain the topics?
    Thanks & regards
    Dharani Barman

    Just call the function from PL/SQl or SQL in your Forms code - it shoudl all work providing that the user you are connected as has access to and execution rights on that function, and that the function uses parameters and return types that are compatible with the version of PL/SQL that the Forms engine has.

  • 10g - cache, report contains oracle user defined function

    hi, experts,
    from http://obiee101.blogspot.com/2008/07/obiee-cache-management.html
    Reasons Why a Query is Not Added to the Cache:
    •Non-cacheable SQL element. If a SQL request contains Current_Timestamp, Current_Time, Rand, Populate, or a parameter marker then it is not added to the cache.
    •Non-cacheable table. Physical tables in the Oracle BI Server repository can be marked 'noncacheable'. If a query references any non-cacheable table then the query results will not be added to the cache.
    •Cache hit. In general, if the query gets a cache hit on a previously cached query, then the results of the current query are not added to the cache. The exception is query hits that are aggregate roll-up hits.
    •Result set is too big.
    Query is cancelled. This can happen by explicit cancellation from Oracle BI Presentation Services or the Administration Tool, or implicitly through timeout.
    •Oracle BI Server is clustered. Queries that fall into the ‘cache seeding’ family are propagated throughout the cluster. Other queries continue to be stored locally. Therefore, even though a query may be put into the cache on Oracle BI Server node 1, it may not be on Oracle BI Server node 2.
    I would like to know
    if the request (report on dashboard) calls an oracle user defined function,  can the cache be created and saved for this report?
    thank you very much!

    Hi stephen,
    if the request (report on dashboard) calls an oracle user defined function, can the cache be created and saved for this report?Yes,it is cached.....function defined in database is called in OBIEE is cached and saved.
    More information and example can be found here http://oraclebizint.wordpress.com/2007/09/10/oracle-bi-ee-10133-support-for-native-database-functions-and-aggregates/
    Hope it helps you.Check all other questions you posted are answered?
    By,
    KK

  • Using Xquery predefined functions in User defined functions

    Hi All,
    I have a requirement of calling a user defined function in osb xquery file.In that function i have to use osb predefined string functions but they are not working it shows error message in xquery file.Can you please suggest how to use them in user defined functions.
    Thanks,
    Srinivas.

    Hi Eric,
    I have a Proxy service it reads mfl data and transform to some other schema.In this Transformation one element data is taken and we have to manipulate that data
    based on the incoming value and return .For this process i took one function and i have to check weather it contains some symbols like ^,~ so i used contains function of
    String with and with out prefix with if else condition it gives error "Unexpected token if"
    declare function insp:buildReferenceRange($inRange as xs:string)
    as xs:string
    let $low:=""
    l
    if(contains($inRange,"^")) //"Unexpected token if"
    name space and prefix are defined in the top of file.
    Thanks,
    Srinivas.

  • USER DEFINED FUNCTION in the formula editor

    How do you create a USER DEFINED FUNCTION in the formula editor using BADI

    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/04/f3683c05ea4464e10000000a114084/frameset.htm">This</a> may help.

  • Accessing a Cache From an Oracle CQL User-Defined Function

    According to the docs ...
    I am to use the following element to set the cache property in my bean...
    <wlevs:property name="cache" ref="cache-id"/>
    However, when I set it, the assembly does not validate.
    If I use <property>, I get a NullPointerException on each request when my processor runs.
    Using the same CQL code..
    Without the <property> tag, the call to the user-defined function works (but I don't have the cache attribute set obviously).
    Here is the excerpt from my assembly...
    <bean id="cacheFunction" class="ou.cep.function.CacheFunction">
    <property name="cache" ref="myCache"/>
    </bean>
    <!-- The default processor for OCEP 11.0.0.0 is CQL -->
    <wlevs:processor id="myProcessor">
    <wlevs:listener ref="CacheChannel"/>
    <wlevs:function ref="cacheFunction" function-name="isValidID" exec-method="isValidID">
    </wlevs:function>
    </wlevs:processor>
    To repeat, with the same CQL with the user-defined function call, if I remove the property element from the bean definition, I can call the function successfully (it just doesn't do what I need it to do). In this case, I am still using the ref=cacheFunction for the wlevs:function within the processor.
    What am I doing wrong?
    Edited by: fl0at on Oct 5, 2010 12:22 PM
    Edited by: fl0at on Oct 5, 2010 12:28 PM

    The case is solved, not sure I could explain why, but...
    This implementation of the user-defined function was a migration from an implementation using the same cache in the join. So, when I removed the cache reference in the source stream (where I am now executing a function that accesses the cache), the problem went away and everything is working.
    I can explain further if there are questions.
    If anyone has thoughts on this, please advise.
    As always, thanks for the help.

Maybe you are looking for