Results 1 to 3 of 3

Thread: help on sql using command

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    138

    help on sql using command

    I'm writing a crystal report using command.

    I have 2 tables that needs to be extracted. I'm extraction field deal_no,action_dt from table events and posn_dt from table posnrpt


    Table Name:events
    field: deal_no, action_dt

    Table Name: posnrpt
    field: posn_dt

    Below are my records from table events in sql database


    deal_no|action_dt|posn_dt
    33|2011-12-23 00:00:00.000|2010-03-31 00:00:00.000
    33|2012-03-23 00:00:00.000|2010-03-31 00:00:00.000
    33|2012-03-23 00:00:00.000|2010-03-31 00:00:00.000
    34|2010-09-28 00:00:00.000|2010-04-08 00:00:00.000
    34|2012-09-28 00:00:00.000|2010-04-12 00:00:00.000
    34|2013-09-28 00:00:00.000|2010-04-12 00:00:00.000

    For example my posnrpt.posn_dt is "21/03/2012" and I'm trying to extract data from both table that
    display deal no with action date closest to posn_dt="21/03/2012" which must be greater or equal.

    my output should be like below

    deal_no action_dt posn_dt
    33 2012-03-23 00:00:00.000 2010-03-31 00:00:00.000
    34 2012-09-28 00:00:00.000 2010-04-12 00:00:00.000

    Note: I had to rewrite the problem again since it was not clear in the beginning. Hopefully this one clear the clouds. Thanks hack for moving this thread to the right location.
    Last edited by mizee; Apr 15th, 2010 at 09:34 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help on sql using command

    Questions concerning writing SQL should go in the Database Development section, which is where I've moved your thread.

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: help on sql using command

    I'm not sure i follow you.
    Do you want a between functionality?

    action_dt between to_date ('15/06/2011', 'mm/dd/yyyy') and to_date ('17/06/2011', 'mm/dd/yyyy')
    ?

    P.S. Not sure to_date works like this or need a format to_date('20010725','YYYYMMDD'), check it.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width