Variables involving dates

Hi,
Inside a query, I have a variable called @refdt1 whose value is set when we input a date in Query - Selection Criteria box.
declare @refdt1 date
set @refdt1 =
/* select @refdt1 from jdt1 t0 where t0.RefDate*/  '[%1]'
I want to create another variable called @refdt2 such that whatever date is input in Selection Criteria, @refdate2 should always give the end of the month.
For ex, if we input 01.05.11 (1 May 2011), @refdate2 should give 31.05.11 (31 May 2011) in same date format as @refdt1.
If we input 15.06.11 (15 Jun 2011), @refdate2 should give 30.06.11 (30 Jun 2011)
If we ignore the problem of February and leap years, then:
(a) MONTH(@refdt1) IN ('1', '3', '5', '7, '8', '10', '12' ) should give 31 as day
(b) MONTH(@refdt1) IN ('4', 6', '9', '11' ) should give 30 as day
Using concatenation and convert, I think we can build up @refdt2, but I don't know how to do it.
Grateful if anybody could show me how to write the code for @refdt2.
The code should be usable anywhere inside the query.
For ex, I could write:
WHERE T0.RefDate <= @refdt2
Thanks
Leon Lai

Hi,
I am making an effort to solve the problem using a particular field in a temporary table instead of a variable @refdt2.
I made this code. As illustration only, each code builds from the previous one, to see where the bug is.
declare @refdt1 date
set @refdt1 =
/*select 1 from jdt1 t0 where t0.RefDate*/  '[%1]'
CREATE TABLE #dates
(Col1 varchar(max),
Col2 int,
Col3 int,
Col4 varchar(max),
Col5 date)
INSERT INTO #dates VALUES
'31',
MONTH(@refdt1),
YEAR(@refdt1),
'31'   +  '/' +    cast (MONTH(@refdt1) as varchar )  +'/'   +
right( cast(   YEAR(@refdt1) as varchar) ,2),
CONVERT(DATE,('31'   +  '/' +    cast (MONTH(@refdt1) as varchar )  +'/'   + 
right( cast(  YEAR(@refdt1) as varchar) ,2)) , 103)
select * from #dates
The error lies in the code CONVERT(DATE ....
Error Msg:
Convert failed when converting date and/or time from character string
Can anyone help me correct that line - to convert the long string to a proper date?
Thanks
Leon

Similar Messages

  • Passing Session variable of DATE data type to opaque view filter

    Hi Everyone,
    Can you guys please help me in passing session variable of DATE data type in RPD's physical layer 'opaque view' filter for Oracle database
    I tried following syntax, syntax wise I didn't got getting any error, but at the same time this opaque view is not fetching any records as well. my session variable is "END_DATE" and its value is 1998/12/31:00:00:00(as shown in RPD session windows, datatype is DATETIME)
    SELECT AMOUNT_SOLD, CHANNEL_ID, CUST_ID, PROD_ID, PROMO_ID, QUANTITY_SOLD, TIME_ID FROM SH.SALES
    WHERE TIME_ID =TO_DATE( 'VALUEOF(NQ_SESSION.END_DATE)','MM/DD/YYYY')
    SELECT AMOUNT_SOLD, CHANNEL_ID, CUST_ID, PROD_ID, PROMO_ID, QUANTITY_SOLD, TIME_ID FROM SH.SALES
    WHERE TIME_ID = TO_DATE( 'VALUEOF(NQ_SESSION."END_DATE")','MM/DD/YYYY')
    SELECT AMOUNT_SOLD, CHANNEL_ID, CUST_ID, PROD_ID, PROMO_ID, QUANTITY_SOLD, TIME_ID FROM SH.SALES
    WHERE TRUNC(TIME_ID) = TO_DATE( 'VALUEOF(NQ_SESSION."END_DATE")','MM/DD/YYYY')
    In past, I was able to pass a session variable into a opaque view filter using DATEOF function, but that was in DB2.
    I appreciate your time and help

    Finally, I got right format. here it is
    to_date(substr('valueof(NQ_SESSION.END_DATE)',1,10), 'yyyy-mm-dd')
    and here is the source from where I got this information
    Using OBIEE Session Variables in Select Tables in the Physical Layer

  • The sme variable in data selection of inpopackage and value in transfer rul

    Hello
    I would like to use the same variable in data selection of infopackage (1) and as a value in transfer rules (2).
    Example :
    If I pass 1 I want to see value1 in data selection of infopackage (1) and as a value in transfer rules (2).
    If I pass 2 I want to see value2 in data selection of infopackage (1) and as a value in transfer rules (2).
    How is possible?

    Hi Aleks,
    In the transfer routine your code would be something similar to this:
    zvar is a variable
    select LOW from RSLDPSEL into zvar where LOGDPID = '<Technical name of Infopackage>' and IOBJNM = '<The Info-object whose value you want to use>'.
    *Now assign the value
    RESULT = zvar.
    Hope this helps.
    Bye
    Dinesh

  • How to deal with variable length data struct in C/JNI

    I have another JNI related question. How do you handle variable length
    data structures in Java and pointer to a pointer?
    Basically, I have a backend in C which has records but we don't know
    how many. The API looks like
    typedef struct rec_list_s {
    int rec_list_cnt;
    rec_list_data_t rec_list_data[1];
    } rec_list_t;
    int rec_list_show(void handle, rec_list_t *list_ptr);
    /* Code snippet for rec_list_show */
    int rec_list_show(void handle, rec_list_t *list_ptr)
    rec_list_t *ptr;
    sz = sizeof (rec_list_t) +
    ((record_count - 1) * sizeof (rec_list_data_t));
    ptr = malloc(sz);
    /* fill the data */
    *list_ptr = ptr;
    return (0);
    So I need to wrap rec_list_show() in JNI call so I can have Java call
    it. How do i pass a pointer to a pointer from Java? I tried in the
    native C code for JNI to return the pointer to pointer as a result
    and store in a member in the Java class rec_list_t and then I pass
    that to JNI call for rec_list_show. The C backend code was fine
    since it got the pointer to pointer but Java become unhappy when
    the object it was referencing changed memory location (I suspect
    the garbage collection becomes unhappy).
    So what would be a good way to deal with this kind of code?
    Thanks,
    Sunay
    Edited by: st9 on Aug 30, 2010 5:47 PM

    I did not imply that you don't know C but you are implying that I don't understand C. Perhaps
    google Sunay Tripathi and click I am feeling lucky so that we don't get into teaching C
    discussions :) On the other hand, I am definitely looking for someone to teach me Java
    otherwise I wouldn't be asking.
    Anyway, let me explain again. The sample function rec_list_show() runs on the backend. It
    is a different process with a different VM space. It of course knows the size of the array
    and what to fill in. As a caller to that API (which is a separate process), I don't know
    what that size is but I need to get the size and corresponding data in one shot because
    the backend locks the table when its providing me the info to make sure its synchronous.
    Now I (the Java process) needs to get that count and data in one shot. Since the C library
    underneath me (wrapped around my JNI interface) has private IPC mechanism to copy
    the contiguous memory from the backend into my memory space, all I need is to provide
    a pointer to a pointer which gets filled in by backend and is available to my process. So
    my equivalent C frontend just passes a pointer to a pointer and casts the return value in
    rec_list_t. The rec_list_cnt tells it how many members it got. The first member is part of
    the struct itself but then following members are right after.
    Another way to help you understand this is with this code snippet from front end C program
    rec_list_t     *ptr, *save_ptr;
    rec_list_data_t *data_ptr;
    int          cnt;
    save_ptr = ptr = malloc(sizeof(rec_list_t));
    rec_list_show(handle, &ptr);
    assert(save_ptr != ptr);
    cnt = ptr->rec_list_cnt;
    for (i = 0; i < cnt; i++) {
         data_ptr = &ptr->rec_list_data;
    Notice the assert(). Also notice the for loop. How do I expect to walk more that one
    member when rec_list_data is a fixed size array of one member?typedef struct rec_list_s {
         int               rec_list_cnt;
         rec_list_data_t          rec_list_data[1];
    } rec_list_t;
    Anyway, I do understand that Java will not allow me to get a reference to a long and
    how Java memory management works. But the JNI native implementation is C
    and I was wondering if people have managed to do some tricks there between C
    and Java.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Using Global Variables in Data Quality Address Cleanse Transforms

    I am currently developing in Data Services 12.2.
    I am trying to dynamically populate the List Owner information in the option tabs of the USA Regulatory Address Cleanse by using global variables.  It populates the 3553 with the variable name instead of the value assigned.
    According to the Technical Manual, it is possible to use global variables in Data Quality Address Cleanse transforms:
    However, you can use substitution parameters in all places where global variables are supported, for example:
    Query transform WHERE clauses
    Mappings
    SQL transform SQL statement identifiers
    Flat-file options
    User-defined transforms
    Address cleanse transform options
    Matching thresholds
    Does anyone know if it is possible to use global variables in the option tab of the Address Cleanse; if so, can you describe how it is done?
    Thanks in advance,
    Rick

    Hi,
    U can refer to the following links in help.sap.com
    GlobalContainer Object
    http://help.sap.com/saphelp_nw04/helpdata/en/75/8e0f8f3b0c2e4ea5f8d8f9faa9461a/content.htm
    Container Object
    http://help.sap.com/saphelp_nw04/helpdata/en/78/b4ea10263c404599ec6edabf59aa6c/content.htm
    Also some of the RUN TIME CONSTANTS are available in your BPM. So if you are trying to retrieve those variables in your Mapping(that is used in BPM), also read the following thread.
    Re: Message id in BPM
    Cheers,
    Siva Maranani.

  • Problem with customer exit variable on date range

    Hi All,
    I have customer exit variable on date range. In the selection screen it has to give the week range  as a default (05/21/2009 to 05/27/2009).
    Earlier its working fine and from yesterday onwards it is not working properly. yesday onwards default date range was not displaying in selection screen.
    Wht would be the problem.
    Thanks in Advance

    Hi Ashish,
    I checked every thing what u told earlier. Every thing is fine.
    And another thing is
    I have routine in infopackage level. Since day before yesterday it was working fine and yesterday onwards it was not working.
    Eg: budat will take the data based on routine for the week. But yesterday onwards it is not picking up the data.however I have the data in datasource for the week.
    Wht would be the problem. I debuged the code and its working fine.
    Sekhar

  • How to declare a bind variable with 'date' data type in command prompt?

    how to declare a bind variable with 'date' data type in command prompt?
    sql>variable q date;
    when i execute it show list of datatypes

    Hi,
    As Lokanath said, there are no DATE bind variables.
    You can use a VARCHAR2 bind variable, and convert it to a DATE in your SQL statment.
    If you're using SQL*Plus, consider a substitution variable. It won't be as efficient as a bind variable, but it will be as convenient.
    For example:
    DEFINE  first_entrry_date = "DATE '2010-06-20''
    SELECT   ...
    WHERE   entry_date >= &first_entry_date
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • What format to input $currentdate(datetime) Global Variable in Data Services Management Console?

    What is the correct input format for the datetime Global Variable in Data Services Management Console? 
    I've tried several formats and keep getting a syntax error. 
    The DSMC is Version: 14.0.3.451
    I'm a new user and learning as I go.  
    Thanks for your help. 

    Hi,
    if you get syntax error as below,
      Syntax error at line <1>: <>: near <.04> found <a float> expecting <+, ||, DIVIDE, MOD, *, SUBVARIABLE, a decimal>.
      1 error(s), 0 warning(s).
      Check and fix the syntax and retry the operation.
      Error parsing global variable values from the command line: <$sedate=2014.12.04 12:00:00;>.
    Check the syntax and try again.
    solution is simple
    Place the global variable value in single quotes '2014.12.04 12:00:00'

  • Where does substitution variable meta data stored?

    where does substitution variable meta data stored in the essbase folder?<BR>Thanks<BR>Arun

    I believe substitution variables are stored in the Essbase.sec (Security file).

  • Passing variables between data tag and Java

    Hello all,
    I have a question about using variables between data tag and java.
    Let me explain.
    I would like to populate variable "Test" with
    the information returned by jbo data tag library.
    <code>
    <% String Test = "%><jbo:ShowValue datasource="ds" dataitem="Cod" /><%";%>
    or
    <% String Test = "<jbo:ShowValue datasource="ds" dataitem="Cod" />";%>
    </code>
    This code did not work.
    Some suggestions
    Thanks
    Humberto
    null

    Humberto,
    I'm afraid I do not know the specific answer
    to your question (perhaps Juan the Data Tag
    Wizard will reply ;-). I vaguely recall
    struggling with teh same issue when I was
    playing with the tags for a demo. Here
    is a hack-around lifted from my demo
    that might help:
    <jbo:Row id="privRow" action="CURRENT" datasource="privileges" />
    <%
    String privName = (String)privRow.getAttribute("Privilegename");
    %>
    In other words, I ended up using the Row
    tag to get a local Java variable bound to the
    row instance and then used its methods
    to extract the value. I presume the class
    of the row instance is oracle.jbo.Row
    and you can lookup its supported methods
    in the reference doc.
    I'd be interested to hear if their is a more
    elegant way - the one suggested above is
    pretty tedious.
    Regards,
    Bill
    ----

  • Problem in comparing a character variable to date value.

    Hi All,
                 I have a scenario where I am comparing a variable of type c with a database field which is a date.Now the comparison is failing though it should not.I can't change the variable because I am capturing that from Line selection ie through get cursor.
    So is there any FM or any other way through which i can change this value to database field value type.
    Also variable has date in format 17.12.207 where as in table it is stored as 20071217 i.e YYYYMMDD.
    Thanks in Advance,
    Saket.

    Hi saket,
    Use  as the code below;
    data : chr_date(10) type c value '12.12.2007'.
    data : lf_date type d.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
      EXPORTING
        date_external                  = chr_date
    IMPORTING
       DATE_INTERNAL                  = lf_date.
    Now you can compare lf_date with database date field.
    Revert back if u have any doubts.
    Regards
    Karthik D
    Edited by: Karthik D on Sep 20, 2008 7:53 PM

  • ActiveX in BradySoft (CodeSoft) - What Class/Method/Object's would I use to send variable form data to BradySoft?

    What Class/Method/Object's would I use to send variable form data to BradySoft? I have a basic label setup in BradySoft and I want to send it variable form data (a serial number) from Labview ActiveX. I have attached Brady's ActiveX programmers guide but can't figure out what to use for this. P.S. I would call Brady or TekLynx tech support about this but they have a strict policy whereas BradySoft supports ActiveX but their tech support doesn't provide programming help with it. I figured I'd try the NI Forums.  

    Aaronb, I presume by publishing an ActiveX programmers manual the BradySoft software installs Active X objects. You may choose to interact with these objects within LabVIEW using Active X controls. The following link will provide a starting point for LabVIEW help topics on Active X communication: Select ActiveX Object Dialog Box
    http://zone.ni.com/reference/en-XX/help/371361F-01/lvdialog/insert_active_x_object/
    Building a Simple Web Browser Using ActiveX (Example of ActiveX arcitecture)
    http://zone.ni.com/devzone/cda/epd/p/id/81 Hope this helps provide a bit of guidance. Cheers!  

  • Defining a Variable in Data Flow

    Hello, all.
    I'm in the process of relearning SSIS after a year-long hiatus and I was in the process of learning back then.
    I'm trying to streamline a SQL stored procedure and I need to define a variable for use in a Derived Column task. Unfortunately, I haven't a clue how to do it. I've searched online, but I've yet to find anything that gels into something clear in my head.
    Anyway, the variable definition is;
    DECLARE @PreviousInputDate DATETIME
    SELECT
    @PreviousInputDate = Max([Input Date])
    FROM
    Staging2
    I need to create the variable so that its scope includes all tasks in the data flow.
    I'll keep digging around, but thanx in advance for any help!

    You can create the variable at data flow scope. Select data flow task (dont double click!) and click on variables in menu to open variables window on left. Then create your new variable. use it in ResultSet tab of above execute sql task after setting ResultSet
    option to Single Row. The  sql statement can just be this
    SELECT
    PreviousInputDate = Max([Input Date])
    FROM
    Staging2
    Then in resultset tab map PreviousInputDate  to your variable.
    Then inside derived column you can fetch it from variables collection like below.
    Just drag the variable to expression area to access it
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • FUNCTION Variable within Data Template

    Hi Im calling a function within my sql and i want to use the result as a bind variable.... here goes...
    Data Template...... XML
    <sqlStatement name="Q1">
    <![CDATA[select function_name(ppp.id) the_main_one,
    :the_main_one + 10 new_value
    from per_ppp]]>
    </sqlStatement>
    I get null value .... but from the_main_one i get a value..... any ideas... i checked for number and nvl(,0) and all that no luck
    is there a grouping thing involved here... where as i need to call the function from within another sql statement...

    It can be done.
    Step 1: Setup package.
    Step 2: Create a global variable for your function value
    Step 3: Before the calling function returns the value, set a global variable (placeholder)
    Step 4: Create a new function that returns the global variable, make sure it's after the first function call. Returning the value you might want to reset the global variable to null....
    Your good to go.
    Ike Wiggins
    http://bipublisher.blogspot.com

  • User defined variables transfer data

    Hello
    I am using the etherCAT 9144 chassis and this hardware supports only target scoped FIFO. After a search, I realized that the only way to transfer data from FPGA to Host is by using User defined variables. But these variables do not support FIFO concept. So, which is the best practice to transfer data after measurements ( e.x 10Hz measurement of 15 values ) to host VI ?
    Thanks
    Solved!
    Go to Solution.

    As mentioned, the 9144 only supports scan engine.
    As for what you should do, that really depends on the whole application. For example, what is the master? Are there other systems involved here? Etc. This is a good read in general, although it might not help right this second: http://www.ni.com/white-paper/14151/en/
    From a high level you should decide what you need. If you need deterministic, low latency communication over longer distances from an RT controller, the 9144 is probably the right choice. If you need low-latency+streaming over short distances from an RT controller, you should look into the MXI RIO chassis. If you primarily need non-deterministic low speed (10 hz) data mixed with low-throughput streaming over long distances from a windows or RT host, then the ethernet rio expansion (9146,7,8,9) is probably the right choice. If you need high speed streaming with low latency control over long distances from a windows or RT host, you need a full cRIO controller. Based on what you've posted so far, its uncertain what is the right fit.
    Lets say you're stuck with the 9144 for now. Given that you can easily hit 1 kHz scan cycles, it should be perfectly achievable to "stream" data at 10 Hz. If you run scan engine at 1 kHz then you're oversampling by 100x. Where it gets tricky is that sync requirement. By default the I/O acquisition is synchronized to the scan clock (and you can see when the scan clock is set through an FPGA I/O node). However, you can take full control of a module in the FPGA and read the I/O at any time you please. That is, you can set it up so when DIO0 goes high you immediately sample all 15 AI values. You can then transfer those latched AI values to the host using user defined variables.

Maybe you are looking for

  • Lightroom to PS CS4

    I have two problems at the moment. Since upgrading to CS4 I cannot link to Bridge, the message is "Photoshop unable to find java script plug-in". I can open Bridge from the Applications folder but not from Photoshop. The other problem that has sudden

  • Some how 10.5 version got on my computer and my itune music is all distorted and scratchy

    Help I have windows xp and the 10.5 version of itunes has made my playback of songs all distorted and scratchy, i.e. like a hollow tin can.  Help... does anyone have info on a solution yet.

  • Mail body with bold characters

    hello , i have the following body to be sent in a mail form oracle forms l_message := '----*** This mail has been automatically generated by The Security Report Management System----*****'||           'This is to inform you that a new incident has be

  • Mrtg no longer updates, perl errors

    When running mrtg, I'm getting this output: # LANG=C mrtg /home/mrtg/cfg/mrtg.cfg Constant subroutine SNMP_Session::AF_INET6 redefined at /usr/share/perl5/core_perl/Exporter.pm line 67. at /usr/bin/../lib/mrtg2/SNMP_Session.pm line 149 Prototype mism

  • Problem in BAPI_ROUTING_CREATE

    Hi Friends, I am trying to create ROUTING by BAPI_ROUTING_CREATE,but it's giving me some errors like, W CPCC_DT              009 The valid-from data has been set from today's date E CPWB                 210 Enter unit of measure E CPCL