SQL Organise via dates and match via logic

<p>
Dear All,
<strong>
My apologies I missed out what makes it a little hard. Please read below:</strong>
I have a a table like these:
custDetails
custID custName
11112 John Smith
11113 Jane Smyth
11114 Barry Bell
11115 Jonny Ball
faultDetail
custID Time&Date Description
11112 28/10/08 08:00:00 Started Work
11112 28/10/08 08:10:00 Did report
11112 28/10/08 09:00:00 Fixed Car
11112 28/10/08 09:10:00 Drove Car to cust house
11112 28/10/08 09:10:12 Cust got car
11113 29/10/08 08:00:00 Started Work
11113 29/10/08 08:20:00 Did report
11113 29/10/08 08:30:00 Fixed Carr
11113 29/10/08 08:40:00 Drove Car to cust house
11113 29/10/08 08:40:00 Cust not in
11113 29/10/08 08:40:00 Drove Car to cust house
11113 29/10/08 08:43:00 Cust got car
11114 29/10/08 08:00:00 Started Work
11114 29/10/08 08:20:00 Did report
11114 29/10/08 08:30:00 Fixed Carr
11114 29/10/08 08:40:00 Drove Car to cust house
11114 29/10/08 08:40:00 Cust not in
11114 29/10/08 08:40:00 Drove Car to cust house
11114 29/10/08 08:43:00 Cust not in left car at garrage
<strong>11114 29/10/08 08:45:00 Cust got car</strong>
11115 29/10/08 08:00:00 Started Work
11115 29/10/08 08:20:00 Did report
11115 29/10/08 08:30:00 Fixed Carr
11115 29/10/08 08:40:00 Drove Car to cust house
11115 29/10/08 08:40:00 Cust not in left car at garrage
11115 29/10/08 08:40:00 Drove Car to cust house
<strong>11115 29/10/08 08:41:01 Got a burger and chips</strong>
11115 29/10/08 08:43:00 Cust got car
All I want to know is whether the customer got their car back by us or they got it from the garage. I have outlined 4 scenarios
11112 customer gets there car back no issues..
11113 customer gets there car back on the second attempt.
11114 customer keeps not being in so we ask them to pick it up from the <strong>garage cust picks it up from garage</strong>.
11115 customer keeps not being in so we ask them to pick it up from the garage, but for what ever reason we end up dropping it off anyway.
The desired output to did the customer get there car back by us.
1112 Yes
1113 Yes
1114 No
1115 Yes
I was hoping someone could help me with this, what is more annoying is that the dates are all jumbled up. How would I go about writing the SQL to create my desired out puts?
<strong>Sorry!</strong>
</p>
Edited by: DaveyB on Oct 28, 2008 3:23 PM
Edited by: DaveyB on Oct 29, 2008 2:18 AM
Edited by: DaveyB on Oct 29, 2008 2:23 AM

Nopparat V. wrote:
I assume that you want the rows with description 'Cust got car' which come after 'Drove Car to cust house' immediately
the follow query may help you. One restriction is that act_date column must be unique for each custid
select custid, max(got_car_by_us) got_car_by_us
from (
select custid,
case when description = 'Cust got car'
and lag(description) over (partition by custid order by act_date) = 'Drove Car to cust house'
then 'Yes'
else 'No'
end got_car_by_us
from faultdetail
group by custid
The rule is
IF we drive the car to the customers house and the customer gets the car then everything is great we get a Yes.
IF we drive the car to the customers house and the customer isn't in and they have to pick it up from the garage then we get a No.
IF we drive the car to the customers house and the customer isn't in and we take it back to the garrage and then they call us up and say can we drop it off again later. WE will then drive the car to the customers house and the customer gets the car then everything is great we get a Yes.
Also they don't always follow in a pattern, as you can see the driver may notes the driver is getting food etc during his journey.
Edited by: DaveyB on Oct 29, 2008 2:13 AM

Similar Messages

  • Sql queries for date and year

    Hi Friends,
    I Have a view named - item_sales with 4 column
    Item code
    Item name
    Transaction_YYYYMM (Date stored in YYYYMM format )
    QTY_RECEIVED
    QTY_SOLD
    Sample data is
    ITEM_CODE ITEM NAME  TRANSACTION_YYYMM     QTY_RECD    QTY_SOLD
    AX             TSHIRT                201307                             3000               2000
    AX             TSHIRT                201308                             2000               500
    AX             TSHIRT                201309                             1000              3000
    CX             XLSHIRT              201307                              3000             2000
    CX             XLSHIRT              201308                              3000             2500
    CX             XLSHIRT             201309                               3000             2500
    EVERY MONTH END I WILL RUN THIS QUERY TO FIND OUT THE BELOW DETAILS
    1. TO FIND ITEM_NAME WISE  -  QTY_RECEIVED AND QTY_SOLD ( FOR CURRENT MONTH - EXAMPLE SEP )
    2. TO FIND ITEM_NAME WISE  -  QTY_RECEIVED AND QTY_SOLD   (FOR CURRENT YEAR EXAMPLE FROM JAN TO SEP )
    OUTPUT FOR SEPTEMBER MONTH LOOK LIKE THIS
                                                            SEP-MONTH                              JAN TO SEP
    ITEM_CODE   ITEM_NAME    QTY_RECEIVED  QTY_SOLD      QTY_RECEIVED  QTY_SOLD
    AX                TSHIRT                   1000                 3000                 6000                 5500
    CX                XLSHIRT                  3000                2000                 9000                 7000
    Pls advise me how to write queries for this
    Rdk

    Just FYI, you *can* edit your own posts, you know
    Rdk wrote:
    Transaction_YYYYMM (Date stored in YYYYMM format )
    First "problem". Don't store dates as string. Store them as dates. It will save you so much headache don't the road you won't believe it.
    True, this is a view, so maybe not as critical - assuming the underlying *DATA* is actually a date.
    1. TO FIND ITEM_NAME WISE  -  QTY_RECEIVED AND QTY_SOLD ( FOR CURRENT MONTH - EXAMPLE SEP )
    2. TO FIND ITEM_NAME WISE  -  QTY_RECEIVED AND QTY_SOLD   (FOR CURRENT YEAR EXAMPLE FROM JAN TO SEP )
    So yeah, based on these requirements, I'd recommend you make that column a DATE, not a string. Dates are easier to parse for date-related logic - such as month by month as you need here.
    Using that, here's one way to do it:
    with w_data as (
          select 'AX' item_code, 'TSHIRT ' item_name, to_date('20130701','yyyymmdd') trans_dt, 3000 qty_recd, 2000 qty_sold from dual union all
          select 'AX'          , 'TSHIRT '          , to_date('20130801','yyyymmdd')         , 2000         , 500           from dual union all
          select 'AX'          , 'TSHIRT '          , to_date('20130901','yyyymmdd')         , 1000         , 3000          from dual union all
          select 'CX'          , 'XLSHIRT'          , to_date('20130701','yyyymmdd')         , 3000         , 2000          from dual union all
          select 'CX'          , 'XLSHIRT'          , to_date('20130801','yyyymmdd')         , 3000         , 2500          from dual union all
          select 'CX'          , 'XLSHIRT'          , to_date('20130901','yyyymmdd')         , 3000         , 2500          from dual
       w_base as (
          select item_code, item_name, trans_dt, qty_recd, qty_sold,
                 sum(qty_recd) over (partition by item_code, trunc(trans_dt, 'MM')) mm_recd,
                 sum(qty_sold) over (partition by item_code, trunc(trans_dt, 'MM')) mm_sold,
                 sum(qty_recd) over (partition by item_code, trunc(trans_dt, 'YY')) yy_recd,
                 sum(qty_sold) over (partition by item_code, trunc(trans_dt, 'YY')) yy_sold,
                 row_number() over (partition by item_code order by trans_dt desc) rnum
            from w_data d
    Select item_code, item_name, mm_recd, mm_sold, yy_recd, yy_sold
      from w_base
    where rnum = 1
    IT ITEM_NA    MM_RECD    MM_SOLD    YY_RECD    YY_SOLD
    AX TSHIRT        1000       3000       6000       5500
    CX XLSHIRT       3000       2500       9000       7000

  • Need help in framing an SQL query - Sample data and output required is mentioned.

    Sample data :
    ID Region State
    1 a A1
    2 b A1
    3 c B1
    4 d B1
    Result should be :
    State Region1 Region2
    A1 a b
    B1 c d

    create table #t (id int, region char(1),state char(2))
    insert into #t values (1,'a','a1'),(2,'b','a1'),(3,'c','b1'),(4,'d','b1')
    select state,
     max(case when region in ('a','c') then region end) region1,
      max(case when region in ('b','d') then region end) region2
     from #t
     group by state
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • SQL to check date and send email and Update Record

    Hii,
    USING ASP AND ACCESS
    I am implementing a classified section for my website and I
    am displaying
    everything successfully.
    When the user posts the classified he selects how many days
    he wants his
    POST like 10 days, 20 days or 30 days and i can successfully
    show the posts
    So if the user posts on says 1st of July 2006 and selects 10
    days for his
    post to be showed on my website
    THEN
    8th July 2006 an email shud go to him saying if he wants to
    keep his POST
    for another 10 days, 20 days or 30 days with 3 links
    and IF YES the 1st july 2006 date must be changed to
    Date of Post + Number of days selected initially + Number of
    days selected.
    I am using two columsn in the DB for this date thing one is
    the strPostDate
    and strAddDate
    So basically the number of days selected for the post to be
    shown on the
    website keeps adding up each time the user clicks on the link
    for 10 days,
    20 days or 30 days with 3 links
    please help need it badly :-)

    Hi,<br />How is the date format in the toolbox control panel?<br /><[email protected]> wrote in message <br />news:[email protected]..<br />> OK, my bad. It is doing it as a yyyy-mm-dd format. Which is what I want. <br />> However, if I do go to update the page the good news is the correct date <br />> is in there in the correct format. However, if I click on the date picker, <br />> it starts out as April, 2192 and the scroll bar is over part of the <br />> Thursday dates in the calendar. This is on Firefox/Mac.<br />><br />> Also if I click on the Update Record/Submit button at the bottom of the <br />> page, I get an error saying 'The date format is: mm/dd/yy' which is the <br />> real bug. Sorry for the mixup.

  • How to learn to extract data and group it

    I recently met a guy who is looking to employ some folks. He got in touch with me in LinkedIn. I have done my research and I know he’s a real guy looking for people. I would like to get the job despite of the poor work conditions but I just feel the fear of failing or not being capable to do the job.
    I know I have to try and it will be great if some of you could give some advice on how to do the job or how can I self-learn this. I'm ready to read books and follow instructions. Last year, I did a DBA internship so, I’m familiar with PL/SQL but I didn’t cover information on how to programme or gather data.
    Here’s bit of the job information: "The work is to programme in PL/SQL to extract data and group it. You will learn how to make indexes and work with massive data. You will learn about programming performance in PL-SQL to extract data".
    I have translated the job info from Spanish to English so, I hope you can get what I’m actually looking for. For the ones that can speak Spanish, this is what the guy wrote: "El trabajo es programar en PL/SQL para extraer datos y centralizarlos. Va a aprender a realizar índices y trabajar con datos masivos. Va a aprender mucho sobre performance de programación en PL-SQL para extraer datos".
    Thanks! Gracias!
    Edited by: 2learnOracle on 25-Jan-2013 16:12

    Hi chaituatp,
    For this requirement, I would suggest you to get familiar with how to create VSTO applications, and how SharePoint object model works. Here are some sample code about this:
    How to: Retrieve List Items using JavaScript:
    http://msdn.microsoft.com/en-us/library/hh185007(v=office.14).aspx
    http://msdn.microsoft.com/en-us/library/office/ee534956(v=office.14).aspx
    VSTO application show data in datagridview:
    http://stackoverflow.com/questions/16926275/simple-example-of-vsto-excel-using-a-worksheet-as-a-datasource
    Thanks,
    Qiao
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Qiao Wei
    TechNet Community Support

  • Get SQL Server default data path via ADO/C++?

    Hi,
    I am trying to get the SQL Server default data path via ADO/Visual C++.
    I find the SQL statements that will do that in
    http://stackoverflow.com/questions/1883071/how-do-i-find-the-data-directory-for-a-sql-server-instance/12756990#12756990
    So I just concat all the statements above into a CString object strStatements, then try to open a recordset as follows:
    _RecordsetPtr m_pRecordset;
    m_pRecordset.CreateInstance(__uuidof(Recordset));
    m_pRecordset->Open(_bstrt(strStatements), _variant_t((IDispath *)m_pConnection, true), adOpenDymanic, adLockOptimistic, 0);
    m_pRecordset->MoveFirst(); 
    The last MoveFirst statement will cause com_error, which said
    “ADODB.Recordset error '800a0e78'
    Operation is not allowed when the object is closed.
    It seems that there are no data in the recordset at all. What is the problem?
    Thanks

    Hello,
    Which query statement did you used to get the database data and log file path? Can you get the result by run the query directly with SQL Server Management Studio? For example,  
    SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
    FROM master.sys.master_files
    WHERE database_id = 1 AND file_id = 1
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • I recently tried to update my iPhone 3 software via my mothers Mac book comp - during the upgrade I lost all my music and calendar dates and now the iTunes on my phone has my mothers iTunes detail - how do I get all my info back on the phone?

    I recently tried to update my iPhone 3 software via my mothers Mac book comp - during the upgrade I lost all my music and calendar dates and now the iTunes on my phone has my mothers iTunes detail - how do I get all my info back on the phone?

    Restore it using the computer you normally sync with.

  • How to get the current data and time of SCOM server via SCOM SDK (API) calls?

    Hi,
    I need to read the current date and time of SCOM server via SOM SDK.
    Is there a class in SDK that provides this info ?
    Thanks,
    satheesh

    To get time and date of Alerts of SCOM, You can use following command let "get-scomalert"
    Also, You can refer below links
    http://blog.tyang.org/2013/02/21/using-scom-2012-sdk-to-retrieve-resource-pools-information/
    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer"
    Mai Ali | My blog: Technical

  • How to forward sms messages via email with date and contact received info

    Does anyone know how to forward sms messages via email with date and contact received info.
    Currently when I forward only the body copy of the sms message is sent in the email.

    This is not currently possible. Sorry.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Date and time stamp transfer via Firewire

    Hi
    Having issues with a Sony micromv camcorder transferring digital recordings via fire wire to Apple macbook- the files are transferrred without the date and time stamp on it. Any way around the problem. Thanks

    ebigglesworth,
    I too am curious about Frank's mention of the date and time removal tool.
    As an aside to your comment:
    I'd rather just be able to tell aperture I don't want the time stamp on the image, to remove it some how digitally, if that makes sense. You'd think it could just be backed out in some fashion.
    That's impossible. Your camera made it impossible. Your camera threw out some pixel data of the real picture in favor of replacing it with yellow, white, and black pixels (or whatever color your timestamp is). Basically, the original photo information is completely lost. All you can do is smudge things (in one way or another) and make the best of it. It will never look completely right unless you use a pixel editor (which Aperture is not) and painstakingly put color in, pixel-by-pixel.
    nathan

  • Import data and cofiles via stms

    Hi all,
    I would like to import some data and cofiles via stms in my MiniSAP.
    Only tables are imported without problems. Programs, transactions or other files of the package will not imported.
    The imported objects will be not activate automatically.
    The return code of my package is (0 = green), the status of the import stay at "Import continue".
    Can anyone help me, please.
    Thank you very much.

    Hi,
    Whenever a transport request get released it generates two files automatically at the OS level,ie at the transport directory normally /usr/sap/trans.These two files are called cofiles & datafiles and it gets generated at /usr/sap/trans/cofiles & /usr/sap/trans/data respectivley.Cofiles are the control files and data is the actual data file.
    You can execute the transports only when you have these datafiles & cofiles available at your tarnsport directory.
    If you want to do the transport in other systems,you have to copy these files to the transport directory of the target system or also you can share the same transport directory across different systems.
    Regards,
    Sam

  • By backing up the iTunes Library via saving the iTunes folder on an external drive, is it also backing up all iPad and iPhone backups as well as App Data and Documents from your devices?

    If I backup my iTunes Library by saving the iTunes folder on an external hard drive using the instructions contained in the link below, will it also back up all my iPad and iPhone backups as well as App Data and Documents from my devices? In other words, will it also create backups for the backups? Thank you.
    Back up your iTunes library by copying it to an external drive
    Furthermore, when it is time to restore the iTunes folder I copied to my external drive to a new iTunes program on my new computer, how will it merge the information once I plug in my iPad or iPhone to that new laptop to sync? If I did the iTunes library backup a couple months ago and I've added documents/music/pictures on my devices since then, what will happen when I try to sync it with the new laptop now working off of the iTunes library backup from a couple months ago since the information is no longer the same? Which information will dominate and thus be kept? Will it delete the new information/data/pictures/documents/music off of the devices since it is not on the iTunes program when it syncs?
    Sorry for so many questions, but they are all related to backing up and restoring iTunes. I am not very tech savvy if you cannot tell

    It would be a good idea to look into a bigger hard drive. They are not that expensive any more and can save a lot of headach. This is even more important if you are buying music from the iTunes music store. If you lost those files they are gone.
    The point of having it on your PC and iPod is to have a backup. If the iPod fails, or you need to go back to the DVDs and find they are scratched, or just can not be read you have lost days of work converting and organizing all of those songs.
    Or the iPod could hard drive could fail and then you will have to try to bring all of those files back from DVDs. You end up with a mess since some songs will probably be on multiple DVDs, have different names ect. Trying to reorganize it all can be a pain.

  • Future Check -In date and not displaying images via IPM search profile

    Hi All,
    We have configured Oracle IPM and UCM to work together and UCM as the repository and we are using ODC to index data to IPM.
    We are not able to see some of the documents from the IPM search field. (only some of the documents)
    When we log in to the UCM repository manager we can see future check in date and 'Done' or 'GenWWW' as the Revision status field and 'New' as the Indexer status field.
    Is there any way to force to push to 'Release' state or can we change the Check-in date and time?
    since we are now in the stage of parallel run, it is urgent to sort this issue immediately........
    Because users are not able to see there documents and continue there works......
    Thanks for any immediate response..............
    Thank You
    Edited by: Nir on Mar 20, 2012 4:15 AM
    IS THERE ANYONE TO HELP US?????
    Edited by: Nir on Mar 21, 2012 1:22 AM

    Hi Aditya,
    Those are not releasing as you said. the indexer would not release the content until the said time is reached
    Sometimes those are releasing without meeting it's release date.
    This ODC date field going to map to a date field in IPM is it? Is it just a date field which is get populated with current date?
    Once i checkin a document, it has released as normal.
    Thank you,
    Edited by: Nir on Apr 15, 2012 8:59 PM
    Hi All,
    As i mentioned earlier post some documents has current date as the indexed date and future date as the Release date.
    Thanks
    Edited by: Nir on Apr 15, 2012 9:16 PM

  • Problem with Connection to SQL Server via Servlet (in iPlanet 6 App Server)

    Hi ,
    I am using the iPlanet ApplicationServer 6.0 SP2 for development & testing of an internet application.
    I am facing a problem when I am trying to connect to MS SQL SERVER via the native jdbcodbc driver (obdc32.dll). The error is something like this :
    [26/Jul/2001 11:50:35:7] warning: DriverConnect: (28000): [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '\'.(DB Error: 18456)
    [26/Jul/2001 11:50:35:7] warning: ODBC-027: CreateConn: failed to create connection [new connection]: DSN=fadd,DB=cashbook,USER=test,PASS=xxxxxxxxx
    [26/Jul/2001 11:50:35:7] error: DATA-108: failed to create a data connection wit
    h any of specified drivers
    Error in connecting to the Database for cirrus :java.sql.SQLException: failed to
    create a data connection with any of specified drivers
    java.sql.SQLException: failed to create a data connection with any of specified
    drivers
    at com.netscape.server.jdbc.Driver.afterVerify(Unknown Source)
    at com.netscape.server.jdbc.Driver.connect(Unknown Source)
    at com.netscape.server.jdbc.DataSourceImpl.getConnection(Unknown Source)
    at gefa.util.DBConnection.jdbcConnectionOpen(DBConnection.java:65)
    at gefa.servlet.ServUpload.doPost(ServUpload.java:45)
    at gefa.servlet.ServUpload.doGet(ServUpload.java:29)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
    Source)
    at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unkno
    wn Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at java.lang.Thread.run(Thread.java:479)
    I have configured a DSN with the name "fadd" on the machine with the application server and it used NT authentication. I have supplied an NT userid and password that has appropriate rights on the database "cashbook".
    When I write a java standalone program, it does connect but via a servlet it does not connect.
    Can some guide me with this problem please ?
    Anything one might have observed in the past ? (may be specific to iPlanet ?)
    Thanks a lot in advance
    ~Sunil

    I'm using iPlanet App server as well and experiencing similar problem. I load my SQL Server driver by Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"), then use DriverManager.getDriver() to obtain the Driver.
    However, the Driver returned is not the SQLServerDriver as expected. The Driver returned is com.netscape.server.jdbc.Driver! And then when I do Driver.getConnection("jdbc:microsoft:sqlserver://MyServer"), it throws an SQLException saying that it doesn't accept a jdbc:microsoft:sqlserver subprotocol. Well, of course it doesn't, it's not a microsoft Driver at all.
    I suspect the problem is that the netscape Driver's acceptsURL() method ALWAYS returns true in iPlanet app server, thus when you getDriver(), the netscape Driver is always returned (and always returned as the first one since it's default?). Thus even though the same piece of code works fine as a standalone application, it just doesn't work on iPlanet app server.
    My work around is:
    Class.forName("my.Driver");
    Enumeration enu = DriverManager.getDrivers();
    Driver useThis = null;
    while (enu.hasMoreElements()) {
    Driver d = (Driver)enu.nextElement();
    if (d.getClass().toString().indexOf("my.Driver") > -1) {
    useThis = d;
    Mind that my above code does not have an performance issue. If you look into the source code of how DriverManager get a Driver for a particular URL, it also loads the whole set of available Drivers, then call acceptsURL() method on each of them to find the first "suitable" one. Thus time complexity is the same.
    I know this is not a very elegant solution and it defeats the purpose of having a DriverManager. Does any one else has a better way to solve this problem, like a way to specify the priority of each Driver so that SQLServerDriver is returned before the netscape Driver?
    Thanks a lot.

  • Error "Conversion failed when converting date and/or time from character string" to execute one query in sql 2008 r2, run ok in 2005.

    I have  a table-valued function that run in sql 2005 and when try to execute in sql 2008 r2, return the next "Conversion failed when converting date and/or time from character string".
    USE [Runtime]
    GO
    /****** Object:  UserDefinedFunction [dbo].[f_Pinto_Graf_P_Opt]    Script Date: 06/11/2013 08:47:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE   FUNCTION [dbo].[f_Pinto_Graf_P_Opt] (@fechaInicio datetime, @fechaFin datetime)  
    -- Declaramos la tabla "@Produc_Opt" que será devuelta por la funcion
    RETURNS @Produc_Opt table ( Hora datetime,NSACOS int, NSACOS_opt int)
    AS  
    BEGIN 
    -- Crea el Cursor
    DECLARE cursorHora CURSOR
    READ_ONLY
    FOR SELECT DateTime, Value FROM f_PP_Graficas ('Pinto_CON_SACOS',@fechaInicio, @fechaFin,'Pinto_PRODUCTO')
    -- Declaracion de variables locales
    DECLARE @produc_opt_hora int
    DECLARE @produc_opt_parc int
    DECLARE @nsacos int
    DECLARE @time_parc datetime
    -- Inicializamos VARIABLES
    SET @produc_opt_hora = (SELECT * FROM f_Valor (@fechaFin,'Pinto_PRODUC_OPT'))
    -- Abre y se crea el conjunto del cursor
    OPEN cursorHora
    -- Comenzamos los calculos 
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    /************  BUCLE WHILE QUE SE VA A MOVER A TRAVES DEL CURSOR  ************/
    WHILE (@@fetch_status <> -1)
    BEGIN
    IF (@@fetch_status = -2)
    BEGIN
    -- Terminamos la ejecucion 
    BREAK
    END
    -- REALIZAMOS CÁLCULOS
    SET @produc_opt_parc = (SELECT dbo.f_P_Opt_Parc (@fechaInicio,@time_parc,@produc_opt_hora))
    -- INSERTAMOS VALORES EN LA TABLA
    INSERT @Produc_Opt VALUES (@time_parc,@nsacos, @produc_opt_parc)
    -- Avanzamos el cursor
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    END
    /************  FIN DEL BUCLE QUE SE MUEVE A TRAVES DEL CURSOR  ***************/
    -- Cerramos el cursor
    CLOSE cursorHora
    -- Liberamos  los cursores
    DEALLOCATE cursorHora
    RETURN 
    END

    You can search the forums for that error message and find previous discussions - they all boil down to the same problem.  Somewhere in your query that calls this function, the code invoked implicitly converts from string to date/datetime.  In general,
    this works in any version of sql server if the runtime settings are correct for the format of the string data.  The fact that it works in one server and not in another server suggests that the query executes with different settings - and I'll assume for
    the moment that the format of the data involved in this conversion is consistent within the database/resultset and consistent between the 2 servers. 
    I suggest you read Tibor's guide to the datetime datatype (via the link to his site below) first - then go find the actual code that performs this conversion.  It may not be in the function you posted, since that function also executes other functions. 
    You also did not post the query that calls this function, so this function may not, in fact, be the source of the problem at all. 
    Tibor's site

Maybe you are looking for

  • IPod touch not detected in iTunes.

    Here it goes, I was having some issues with my iTouch so I tried to restore today. After restore was complete iTunes automatically quitted and when i restarted iTunes it said cannot connect to iPhone exxor EX-000065 or something but it was 65 in the

  • Problem in transporting the Customer exit variable

    Hi all, i have careated a variable to capture the current date in my report, with the processing type, Customer Exit. and, its getting populated fine in my DEV environment. basically, i have to compute the number of days, in which net due date is bei

  • Need advice on second db on a 2-node RAC already has a db

    We are going to add a new db to a existing RAC 2 node environment. Currently we have one db on this two node rac ( each node has one instance). I want to be sure I follow oracle best practice on shared oracle home, shared listener, etc. Our environme

  • Process code used for DELFOR inbound idoc

    I have to create one interface in that i have to capture the transfer orders from that i have create the DELFOR idoc which used for posting the scheduling agreements. These agreements will pos teh requirement to the forecast tab. Please let me know t

  • How to save Image from Oracle form!!?

    Hello Every Oracle forms developer i have a from contains block with Blob column ...i store image in it i have used read_image_file to view image in form and insert it into DB 11gR2 now ..* I want to create procedure in form_button to download image