Just a quicky on dates

CREATE TABLE slaughter(
     Slaughter_No               Number(12)PRIMARY KEY,     
     Slaughter_Set               Varchar2(10)NOT NULL,
     Slaughter_Date               DATE,
     Disposal_Slaughterhouse_Code     Varchar2(15)NOT NULL,
     Diagnosis_Confirmation_No      Number(12)NOT NULL,
CONSTRAINT fk_sl_dc FOREIGN KEY (Diagnosis_Confirmation_No)
          references diagnosis(Diagnosis_Confirmation_No),
CONSTRAINT fk_sl_ds FOREIGN KEY (Disposal_Slaughterhouse_Code)
          references disposal_slaughterhouse(Disposal_Slaughterhouse_Code));
All I need to do is to create a query that will show me the Slaughter_No and the date of that particular slaughter, for the all the slaughters that have taken place in for example the last six months
If SQL was made for a simpleton like me I could do this:-
Select slaughter_no, Slaughter_Date
FROM slaughter
WHERE slaughter_date between 28-Feb-01 and 28-Mar-01
(n how I do i get round the fact that the stystem thinks
28-Feb-98 is greater than 28-Feb-01)

SQL> -- If your nls_date_format is set like this:
SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'dd-Mon-yy'
  2  /
Session altered.
SQL> -- Your system will display the date like this:
SQL> SELECT SYSDATE
  2  FROM   DUAL
  3  /
SYSDATE                                
16-Jan-02                              
SQL> -- To see all four year digits:
SQL> SELECT TO_CHAR (SYSDATE, 'dd-Mon-yyyy')
  2  FROM   DUAL
  3  /
TO_CHAR(SYS                            
16-Jan-2002                            
SQL> -- To see the system default date format
SQL> -- and all four year digits:
SQL> SELECT SYSDATE,
  2           TO_CHAR (SYSDATE, 'dd-Mon-yyyy')
  3  FROM   DUAL
  4  /
SYSDATE   TO_CHAR(SYS                  
16-Jan-02 16-Jan-2002                  
SQL> -- If your table is like this
SQL> -- (using the simplified structure
SQL> --  that you sent in your e-mail):
SQL> CREATE TABLE slaughter
  2    (slaughter_no   NUMBER (12)
  3                   PRIMARY KEY,
  4       slaughter_set  VARCHAR2 (10) NOT NULL,
  5       slaughter_date DATE)
  6  /
Table created.
SQL> -- If you insert the system date
SQL> -- into your slaughter_date
SQL> INSERT INTO slaughter
  2  VALUES (1, 'test1', SYSDATE)
  3  /
1 row created.
SQL> -- You can see the default format
SQL> -- and all four year digits like this:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  WHERE  slaughter_no = 1
  6  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           1 16-Jan-02 16-Jan-2002     
SQL> -- You can insert using SYSDATE - number_of_days:
SQL> INSERT INTO slaughter
  2  VALUES (2, 'test2', SYSDATE-180)
  3  /
1 row created.
SQL> -- results:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  WHERE  slaughter_no = 2
  6  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           2 20-Jul-01 20-Jul-2001     
SQL> -- You can insert by converting a character format
SQL> -- to a date format:
SQL> INSERT INTO slaughter
  2  VALUES (3, 'test3', TO_DATE ('28-Feb-2001', 'dd-Mon-yyyy'))
  3  /
1 row created.
SQL> INSERT INTO slaughter
  2  VALUES (4, 'test4', TO_DATE ('28-Mar-2001', 'dd-Mon-yyyy'))
  3  /
1 row created.
SQL> INSERT INTO slaughter
  2  VALUES (5, 'test5', TO_DATE ('28-Feb-1998', 'dd-Mon-yyyy'))
  3  /
1 row created.
SQL> -- results:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  WHERE  slaughter_no IN (3, 4, 5)
  6  ORDER BY slaughter_no
  7  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           3 28-Feb-01 28-Feb-2001     
           4 28-Mar-01 28-Mar-2001     
           5 28-Feb-98 28-Feb-1998     
SQL> -- You can insert using the nls_date_format
SQL> -- and the system will automatically do an
SQL> -- implicit conversion to the date format,
SQL> -- however, if you only give it the last
SQL> -- two digits of the year, you don't know
SQL> -- if if thinks it is 1998 or 2098:
SQL> INSERT INTO slaughter
  2  VALUES (6, 'test6', '28-Feb-98')
  3  /
1 row created.
SQL> INSERT INTO slaughter
  2  VALUES (7, 'test7', '28-Feb-01')
  3  /
1 row created.
SQL> INSERT INTO slaughter
  2  VALUES (8, 'test8', '28-Mar-01')
  3  /
1 row created.
SQL> -- the results:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  WHERE  slaughter_no IN (6, 7, 8)
  6  ORDER BY slaughter_no
  7  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           6 28-Feb-98 28-Feb-2098     
           7 28-Feb-01 28-Feb-2001     
           8 28-Mar-01 28-Mar-2001     
SQL> -- the whole table now looks like:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  ORDER BY slaughter_no
  6  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           1 16-Jan-02 16-Jan-2002     
           2 20-Jul-01 20-Jul-2001     
           3 28-Feb-01 28-Feb-2001     
           4 28-Mar-01 28-Mar-2001     
           5 28-Feb-98 28-Feb-1998     
           6 28-Feb-98 28-Feb-2098     
           7 28-Feb-01 28-Feb-2001     
           8 28-Mar-01 28-Mar-2001     
8 rows selected.
SQL> -- One way to select slaughter_date within the last six
SQL> -- months is to use the add_months function.
SQL> -- Using -6 causes it to subtract six months
SQL> -- from the system date.  So, you are asking for
SQL> -- slaughter_date between the system date minus six months
SQL> -- and the system date:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  WHERE  slaughter_date BETWEEN ADD_MONTHS (SYSDATE, -6)
  6                    AND        SYSDATE
  7  ORDER BY slaughter_no
  8  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           1 16-Jan-02 16-Jan-2002     
           2 20-Jul-01 20-Jul-2001     
SQL> -- Or you can specify between certain dates,
SQL> -- using the full format, to be sure what year you
SQL> -- are asking for:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  WHERE  slaughter_date
  6           BETWEEN TO_DATE ('16-Jul-2001', 'dd-Mon-yyyy')
  7           AND     TO_DATE ('17-Jan-2002', 'dd-Mon-yyyy')
  8  ORDER BY slaughter_no
  9  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           1 16-Jan-02 16-Jan-2002     
           2 20-Jul-01 20-Jul-2001     
SQL> -- Using the values that you provided:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy')
  4  FROM   slaughter
  5  WHERE  slaughter_date
  6           BETWEEN TO_DATE ('28-Feb-2001', 'dd-Mon-yyyy')
  7           AND     TO_DATE ('28-Mar-2001', 'dd-Mon-yyyy')
  8  ORDER BY slaughter_no
  9  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLA     
           3 28-Feb-01 28-Feb-2001     
           4 28-Mar-01 28-Mar-2001     
           7 28-Feb-01 28-Feb-2001     
           8 28-Mar-01 28-Mar-2001     
SQL> -- Remember that if you are using the system date
SQL> -- for input or queries that it includes the time,
SQL> -- so if you are just interested in the date portion,
SQL> -- you may want to use the trunc function.  Note the
SQL> -- differences in the following queries:
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy hh24:mi')
  4  FROM   slaughter
  5  WHERE  slaughter_date BETWEEN ADD_MONTHS (SYSDATE, -6)
  6                    AND        SYSDATE
  7  ORDER BY slaughter_no
  8  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLAUGHTER
           1 16-Jan-02 16-Jan-2002 14:32
           2 20-Jul-01 20-Jul-2001 14:32
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy hh24:mi')
  4  FROM   slaughter
  5  WHERE  TRUNC (slaughter_date)
  6           BETWEEN ADD_MONTHS (SYSDATE, -6)
  7           AND     SYSDATE
  8  ORDER BY slaughter_no
  9  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLAUGHTER
           1 16-Jan-02 16-Jan-2002 14:32
           2 20-Jul-01 20-Jul-2001 14:32
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy hh24:mi')
  4  FROM   slaughter
  5  WHERE  slaughter_date
  6           BETWEEN ADD_MONTHS (TRUNC (SYSDATE), -6)
  7           AND     TRUNC (SYSDATE)
  8  ORDER BY slaughter_no
  9  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLAUGHTER
           2 20-Jul-01 20-Jul-2001 14:32
SQL> SELECT slaughter_no,
  2           slaughter_date,
  3           TO_CHAR (slaughter_date, 'dd-Mon-yyyy hh24:mi')
  4  FROM   slaughter
  5  WHERE  TRUNC (slaughter_date)
  6           BETWEEN ADD_MONTHS (TRUNC (SYSDATE), -6)
  7           AND     TRUNC (SYSDATE)
  8  ORDER BY slaughter_no
  9  /
SLAUGHTER_NO SLAUGHTER TO_CHAR(SLAUGHTER
           1 16-Jan-02 16-Jan-2002 14:32
           2 20-Jul-01 20-Jul-2001 14:32
SQL> -- The above are just a few ideas.
SQL> -- There are many different ways to do things.
SQL> --
SQL> -- One more point, regarding naming
SQL> -- your primary and foreign keys.
SQL> -- If you try to insert a duplicate value
SQL> -- that violates your primary key constraint:
SQL> INSERT INTO slaughter
  2  VALUES (1, 'test9', SYSDATE)
  3  /
INSERT INTO slaughter
ERROR at line 1:
ORA-00001: unique constraint
(SCOTT.SYS_C002996) violated
SQL> -- You get an error message that doens't
SQL> -- tell you much.     However, if you have
SQL> -- a meaningful name for you primary key
SQL> -- and you try the same thing, you get a
SQL> -- more meaningful error message:
SQL> ALTER TABLE slaughter
  2  DROP PRIMARY KEY
  3  /
Table altered.
SQL> ALTER TABLE slaughter
  2  ADD CONSTRAINT slaughter_pk
  3  PRIMARY KEY (slaughter_no)
  4  /
Table altered.
SQL> INSERT INTO slaughter
  2  VALUES (1, 'test9', SYSDATE)
  3  /
INSERT INTO slaughter
ERROR at line 1:
ORA-00001: unique constraint
(SCOTT.SLAUGHTER_PK) violated

Similar Messages

  • Deleted adobe edge animate cc and now creative cloud wont letme redownload file just says up to date

    deleted adobe edge animate cc and now creative cloud wont letme redownload file just says up to date can anyone tell me how to fix this? do i have to delete files to be able to redownload?

    How exactly did you remove the software?  Also which operating system are you using?

  • HT1338 My desktop Pro won't upgrade from it's current format of 10.5.8 it just states up to date software?

    My desktop Pro won't upgrade from it's current format of 10.5.8 it just states up to date software? Please advise my course of action!

    The first step in Upgrading... is to Snow Leopard = OS X 10.6.x
    It is Not available as a download... It is a Paid Upgrade.
    Do this first...
    Check that your Mac meets the System Requirements for Snow Leopard...
    Snow Leopard Tech Specs
    http://support.apple.com/kb/SP575
    If so... Purchase a Snow Leopard Install Disc...
    http://store.apple.com/us/product/MC573Z/A/mac-os-x-106-snow-leopard
    Other countries...
    http://support.apple.com/kb/HE57
    After the Successful Install, run Software Update to get the latest updates for Snow Leopard.
    Be sure to make a Backup of your Current System Before Upgrading...

  • My messages app won't open, after I sent a large iMessage. I think it just has too much data on it. What can I do other then reset my iPhone?

    My messages app won't open, after I sent a large iMessage. I think it just has too much data on it. What can I do other then reset my iPhone?

    Hi everyone, I had this problem but none of the solutions above worked. What happened with me, and with others in other forums, is that a particular thread or message was causing the problem. I'd go to open the message and all I'd get was a white screen with the blue bar at the top. So, I went into contacts, pressed 'send message' to a contact whose message wasn't causing the problem, then I pressed back to messages. You then swipe to the left on the thread that's causing the problem, and delete it. Sadly this means you will lose all that person's messages, but you can try opening it from there and deleting it on the thread. Didn't work for me though. Hope that helps! It was the only thing that worked for me after about three days of total frustration and resetting!

  • I am trying to download the 8.0 and i just bought 20gb of data and it is still not letting me

    i am trying to download the 8.0 and i just bought 20gb of data and it is still not letting me

    haleighgarza1 wrote:
    it says: it requires 4.7GB of storage and to make more storage even though i just bought more
    Ummm..that's iCloud space, not storage on your phone.  What you bought has nothing to do with how much storage is on your phone.
    You must free up space on your phone by deleting apps, photos, music, movies, etc....

  • If I turn on Internet Sharing if I have to get a different plan or does it just impact my current data?

    I really like my Windows Phone. I have a Nokia Lumia 928 too bad Verizon is in bed with Apple, I'd like to know if I turn on Internet Sharing if I have to get a different plan or does it just impact my current data?

        We want you to always get the most out of your device, DaveBootsma! What plan are you currently on? The Nokia Lumia 928 is Mobile Hotspot compatible. If on a More Everything plan the Mobile Hotspot usage is included as part of your data plan.
    Thank you,
    YaleK_VZW
    Follow us on Twitter @VZWsupport

  • Hi just done some up dates on my i phone three it got half way through sync with my phone then the phone turned of and came back on again with the i tune picture and the end of the usb cable. but my phone is plugged into my computer can anyone helphi just

    hi just done some up dates on my i phone three it got half way through sync with my phone then the phone turned of and came back on again with the i tune picture and the end of the usb cable. but my phone is plugged into my computer can anyone help

    Try to force your phone into recovery mode. Disconnect it from the computer's USB cord. Turn it off if you can by holding the sleep/wake switch until you see the red slide to off. If you can't turn it off, please continue. Press and hold the home button while plugging it into the computer's USB cord. Continue holding the Home button while iPhone starts up. While starting up, you will see the Apple logo. When you see "Connect to iTunes" on the screen, you can release the Home button and iTunes will display the recovery mode message.  http://support.apple.com/kb/HT1808
    Then you can restore your phone:  http://support.apple.com/kb/HT1414

  • Help!: syncing with itunes just erased all my data

    is there any way to recover?  I just wanted to copy one app from itunes running on my pc to my ipad.   Now all of my ipad icons are all mixed up (different order than before) and several of my applications are no longer on the ipad.  When I tried to redownload my purchased apps, they came in with no data. 
    This is so frustrating.  I just wanted one new app and and the only reason I went to my pc and itunes was because I could not download the app directly from the app store on the ipad (for some reason Email Chess just wasn't found when searching the app store on the ipad- and I did search for both ipad and iphone apps).
    itunes and the ipad should have much finer control over which direction syncing occurs and whether apps or data can be removed.  at least a warning or something.  I've just lost dozens of hours of data.

    please do not respond unless you read my post completely and thoroughly.  I've seen too many people respond with advice that has nothing to do with the problem that people have stated.

  • I think sync just deleted all my data when I added a device

    Summary:
    1, Added new device,
    2, device did not pull down information it pushed up to sync server
    3, sync server did contain a few mb of data now it contains 19kb
    Please help,
    I added a device using my "Firefox Sync Key" not the three sets of numbers as i did not have access the the original machine that had my profile on it.
    I checked the sync status, and I had a few mb on the history, bookmarks, pref, etc...
    Once my new device had sat there for a while I went back in to check the data usage and it appears that the new device over wrote all my sync data? Sync size is now about 19 kb?
    Please help as i did have some information information up there.
    Tell me what I can do please?
    Thanks,
    Derry

    Thanks, i've tried these, did not work
    in "How do I set up Firefox Sync?" > "Get the code on another computer"
    This is applicable to me:
    But i did not have the device with me, so i entered my user name/password and "Firefox Sync Key" which i had taken from the original device.
    As soon as i completed this I checked "view quota": it said a few mb.
    After about 10 min I checked again and it said 19kb.
    I just tried the reset ensuring merge data was selected.
    And still nothing.
    Thank you for your quick reply.
    Derry

  • How to create an IDoc just with the updated data.

    Hello I have a question regarding IDocs.
    In case I updated an existing material.
    Is there a transaction where I can put a matnr in, that reads the change pointer table and creates an IDOC with just the updated fields for an existing material.
    Like the transaction BD21, for example. But there I just have the possibility to enter a message type and not a material number.
    If there is no standard transaction. What steps do I have to do to achieve this goal?
    Kind regards,
    Tobias

    thanks a lot for your fast answers. but I want to decide weather I want to create a idoc that includes all data for a material (using transaction bd10) or create an idoc that includes just the updated data.
    The program logic should be the following:
    Select all materials in the change pointer table (that have been changed or new created).
    Check what value has been changed.
    If it is value YSAPSYSTEMXX (extension of mara) then create a idoc with all data for the material.
    If not YSAPSYSTEMXX has been changed create an idoc that includes just the updated data.
    For Idocs that include all material data I would use sap standard transaction BD10 and batch-input.
    For Idoc that should only include the changed/updated data I am searching for a corresponding transaction….
    Kind regards,
    Tobias

  • How do I change view of Iphoto's to just thumbnails without the date and size in Imovie?

    How do I change the view on the Iphoto's in Imovie so that just the thumbnails show not thumbnails and date and size?

    copy paste them to a mail program and send them to yourself
    or use evernote and or dropbox to transfer them to the cloud

  • How can i filter just te equipment with date to 31129999 ??

    Hi ,
    How can i filter just te equipment with dateto 31129999 ??  i need just the valid equipment with dateto 31129999 but this char i cant take it to filter, how can i do this?

    In the Update tab of the InfoPackage, you can select the Time-Dependent data. In this, if you only want to extract Equipment Master Data Attributes or Master Data Text for effectivity dates of current date through 31-Dec-9999, you can create a routine for the time interval by updating it as such:
      CONSTANTS: c_max_date TYPE d VALUE '99991231'.
      p_datefrom = sy-datum. "Current Date
      p_dateto   = c_max_date. "Max Date

  • I wish there will be a choice to delete private data whenever i choose quit. so i don't have to go into setting just to delete private data. thanks

    i wish when i press quit there will be a choice whether i want to delete all the private data.it will be just like the desktop version where i can browse in private and close the browser without leaving any trace.

    iamjayakumars this is a Firefox for Android question. You gave a desktop answer. The OP is correct in that there is no way to clear browser history on shutdown at this time on FxA.
    Current nightly builds have private browsing tabs. These builds are for testing at this time. They may leak data or fail to clean data from the session. They are available at http://nightly.mozilla.org

  • Why hasn't Verizon just announced a release date!!

    The galaxy note 2 has already been on preorder for a while and it doesn't ship till the 27th of november, the windows phones are supposed to come out BEFORE thanksgiving and no release date has even been given at all? Are they trying to give people a chance to just order more samsung galaxy notes?

    I preorder the Note 2 for three reasons more ram and faster processor and the Walcom pen. so i would be one of those type of people and it you look around all carriers are charging that price. unless you wait a year until the better process hit the market and they go down in price and if you tying to say the windows phone is going to be better please go ahead an order one. and I will be watch for your post stating that it is locking up just 3 to 6 months after you purchase it. How do i know this I work in IT for a company and a employee had a windows phone. and I have had to hard reset the phone several time in order to get it to stop from locking up. So please buy one and keep us update how bad it is...lol

  • After Upgrade:  No pics, just frame and exif data

    I upgraded yesterday from 1.0 (on XPmedia center05)
    I get the library from 1.0 (no pics, just a blank frame and the exif data)
    I deleted the library and uninstalled and reinstalled twice---same results-
    Any suggestions on how to get an actual picture with the file??

    I have no idea where the 'previews folder' is located and then how to 'rebuild standard previews'????
    At present, I have LR 1.1 and it seems to be fine but for no pics--
    the files edit (curves, exposure, etc.) but I can't see them----
    I have deleted my library (no biggie for me as I hadn't really used that aspect of LR---my main work was in the develop module--

Maybe you are looking for