Adding a summary column in a table which contains the start and end dates in the week

Hi,
I've got a DIMENSION DATE table and want to add in another column which shows the start and end date of the week.
See below, the new column is WEEKOFYEARTEXT.
Does anybody know how i may generate this column using SQL and using the existing columns?
Umar Javed

See:  http://www.sqlusa.com/bestpractices/datetimeconversion/
DECLARE @Year INT = '2015';
WITH cteDays AS (SELECT DayOfYear=Dateadd(dd, number,
CONVERT(DATE, CONVERT(char(4),@Year)+'0101'))
FROM master.dbo.spt_values WHERE type='P'),
CTE AS (SELECT DayOfYear, WeekOfYear=DATEPART(week,DayOfYear)
FROM cteDays WHERE YEAR(DayOfYear)= @YEAR)
SELECT WeekOfYear, StartOfWeek=MIN(DayOfYear), EndOfWeek=MAX(DayOfYear)
FROM CTE GROUP BY WeekOfYear ORDER BY WeekOfYear;
WeekOfYear StartOfWeek EndOfWeek
1 2015-01-01 2015-01-03
2 2015-01-04 2015-01-10
3 2015-01-11 2015-01-17
4 2015-01-18 2015-01-24
5 2015-01-25 2015-01-31
6 2015-02-01 2015-02-07
7 2015-02-08 2015-02-14
8 2015-02-15 2015-02-21
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

Similar Messages

  • SAP CRM Tables and Fields for Contract start and End dates

    Hi Experts,
    Please Provide me SAP CRM Tables and Field names for the below.
    SAP CRM Contracts start date and End date
    SAP CRM Conditions(PROO, K007 etc....) records start and End Date.
    Thanks and Regards,
    Teja

    correction
    10 Replies Latest reply: 24 May, 2013 8:38 AM by nishant Vasudev  
    Tweet
    SAP CRM Tables and Fields for Contract start and End dates
    This question has been Answered.
    Teja Dhar 12 Oct, 2009 8:03 PM  
    Currently Being Moderated
    Hi Experts,
    Please Provide me SAP CRM Tables and Field names for the below.
    SAP CRM Contracts start date and End date
    SAP CRM Conditions(PROO, K007 etc....) records start and End Date.
    Thanks and Regards,
    Teja
    Correct Answer by Sreekantha Gorla  on Oct 22, 2009 8:22 PM
    Hi,
    dates will be stores in the table 'SCAPPTSEG'.
    I double checked it. This table stores all the date types of one order transactions...
    The relationship is as follows..
    CRMD_ORDERADM_H- guid = crmd_link-guid_hi
    crmd_link-guid_set = SCAPPTSEG-APPL_GUID.
    Thanks and regards,
    Sreekanth
    <:footer>See the answer in context
    6281 Views
    Topics: Customer Relationship Management
    Reply
    Average User Rating
    0
    (0 ratings)
    My Rating:
      Rating Saved!
    Comment on your rating
      Re: SAP CRM Tables and Fields for Contract start and End dates
    Robert Jesionowski 14 Oct, 2009 2:23 PM (in response to Teja Dhar)  
    Currently Being Moderated
        Hi, 
    you should try with FM: CRM_DATES_READ_SINGLE_OB or CRM_DATES_READ_DB.
    There is something in table SCAPPT and SCGENAPPT.
    Regards, R
    Report Abuse
    Like (0)
    Reply
      Re: SAP CRM Tables and Fields for Contract start and End dates
    Teja Dhar 22 Oct, 2009 5:30 PM (in response to Robert Jesionowski)  
    Currently Being Moderated
        Hi Robert, 
    I am not able to find contract start date and End dates in the tables SCAPPT and SCGENAPPT.
    Can you suggest some relevant tables.
    Best Regards,
    Teja
    Report Abuse
    Like (0)
    Reply
      Re: SAP CRM Tables and Fields for Contract start and End dates
    Sreekantha Gorla 22 Oct, 2009 2:35 PM (in response to Teja Dhar)  
    Currently Being Moderated
        Hi, 
    Table SCAPPTSEG stores the contract start and end dates.
    Thanks,
    Sreekanth
    Report Abuse
    Like (0)
    Reply
      Re: SAP CRM Tables and Fields for Contract start and End dates
    Teja Dhar 22 Oct, 2009 5:32 PM (in response to Sreekantha Gorla)  
    Currently Being Moderated
        Hi Sreekanth, 
    I am not able to find contract start date and End dates in the table SCAPPTSEG.This is for appointments.
    Can you suggest some relevant tables.
    Best Regards,
    Teja
    Report Abuse
    Like (0)
    Reply
    Correct AnswerRe: SAP CRM Tables and Fields for Contract start and End dates
    Sreekantha Gorla 22 Oct, 2009 8:22 PM (in response to Teja Dhar)  
    Currently Being Moderated
        Hi, 
    dates will be stores in the table 'SCAPPTSEG'.
    I double checked it. This table stores all the date types of one order transactions...
    The relationship is as follows..
    CRMD_ORDERADM_H- guid = crmd_link-guid_hi
    crmd_link-guid_set = SCAPPTSEG-APPL_GUID.
    Thanks and regards,
    Sreekanth
    Report Abuse
    Like (0)
    Reply
      Re: SAP CRM Tables and Fields for Contract start and End dates
    Wim Olieman 23 Oct, 2009 9:12 AM (in response to Sreekantha Gorla)  
    Currently Being Moderated
        Hi, 
    I can tell you where the pricing records are saved, replicated from ECC.
    The data from ECC table Axxx (e.g. A304) is replicated to CRM table
    CNCCRMPRSAPxxx (e.g. CNCCRMPRSAP304).
    Here you can find fields TIMESTAMP_TO and TIMESTAMP_FROM.
    About the dates: what Sreekantha Gorla stated, about table 'SCAPPTSEG' is correct.
    What might help is to execute program "CRM_ORDER_READ". Here you can find
    the relevant entries also.
    regards,
    Wim
    Report Abuse
    Like (0)
    Reply
      Re: SAP CRM Tables and Fields for Contract start and End dates
    Teja Dhar 23 Oct, 2009 4:59 PM (in response to Teja Dhar)  
    Currently Being Moderated
        Hi Experts, 
    Thanks a lot for your support.My problem got resolved.
    Best Regards,
    Teja
    Report Abuse
    Like (0)
    Reply
      Re: SAP CRM Tables and Fields for Contract start and End dates
    rajesh gadamsetty 27 Nov, 2009 12:29 PM (in response to Teja Dhar)  
    Currently Being Moderated
        Hi Teja 
    Please let me know how you got the dates. i got the same requirement
    Report Abuse
    Like (0)
    Reply
    Correction on above mail.
    Hi Sanjay,
    Can you please help me to find the contract st art date and end date fetching from the table as below
    ITEM DATES:
    Select guid_set from table CRMD_LINK where guid_hi              =  CRMD_ORDER_I-GUID AND
                                                                              OBJTYPE_HI     =  '06'
                                                                              OBJTYPE_SET  =  '30'.
    Select * from SCAPPTSEG where APPL_GUID = guid_set.
    as from the table scapptseg has some unusal fields which fields to select to get the start date and end date and on what condition and isuppose we need to convert als the same
    pls suggest further on same
    regards
    Arora

  • Find table which contains "job name" and "Mail sent to users"

    Hi Folks,
    I have a requirement” whenever I run a job(xyz), it send mail to users”, Can you please let me know the table which contains both “job name” and “successfully mail sent to users”.
    Thanks in Advance.
    Lakshmi.

    Hi,
    You can find the job name in TBTCJOB.
    Regards,
    Ravi
    Note : Please mark the helpful answers

  • Comparing two columns in two tables using partial text strings and copying data between tables

    I have two tables:
    The Vendor table is supplied by a clothing manufacturer and lists product data by row with a column that contains a unique manufacturer ID, such as T5C4.  In this table is a short product description and a long product description that I need to find and copy into the second table, Inventory.
    The Inventory table is an export from our Magento store.  Each row contains a unique inventory number in a column that includes but does not match the unique manufacturer ID from the Vendor table.  For example, the unique inventory number could be T5C4-W12, or RED-T5C4W12 or some other variation.
    For each product in Inventory, I need to find the matching product in Vendor, and then copy the short description and long description from Vendor to Inventory.
    Any tips?  Thanks!
    Karl

    Karl,
    Here's a start, as you requested.
    The formula for Our Inventory Row is:
    =IFERROR(MATCH("*"&A&"*", Our Inventory :: A, 0), "n/a")
    The formula for Brief Description in the inventory table is:
    =IFERROR(INDEX(ABC Products :: $A$1:$C$9,MATCH(ROW(), ABC Products :: $D, 0), 2), "n/a")
    The formula for the Full description in the inventory table is:
    =IFERROR(INDEX(ABC Products :: $A$1:$C$9,MATCH(ROW(), ABC Products :: $D, 0), 3), "n/a")
    The Manufacturer's table knows the concise product numbers, so it has the ability to search the Inventory table for it's product id's using wildcards and it then displays the line number of the item in the inventory table. The Inventory table can then search the manufacturer's table for its row number and can reference the brief and full descriptions.
    This approach has a serious limitation. It will only find the first occurrence in the inventory. Now, if you want to accept this, you can sort all the found descriptions and pull them out of the inventory table, and then the next product in line will display it's description too.
    I wish I could do better with this, but it's all I can come up with at this point, knowing only what you have told me.
    Jerry

  • Table which contains the info of last changed person info

    Hi i need the last person who changed the invoice document to put it in a report.
    i can set in MIR4 when i go to display changed documents.
    i tried debugging the standard program but it didnt help.
    can any one tell me in which table these info are stored.
    Thanks in AVD

    Check out CDHDR and CDPOS tables .... in CDHDR check the below fields ...
    USERNAME ABAPP01
    UDATE 01.06.2004
    UTIME 16:48:12

  • Hideing a Column in ALV Table which is Displaying the POWL Query data

    Hi SDNers,
    I want to hide a column of ALV Table which is displaying my POWL Query data in it and hideing should be based on the Role as well. i.e few of the role the column shoudl be hidden and few of the roles should have the Column visible.
    waiting for the Valueble Answers.
    Thanks & Regards,
    Govindu

    Hai Kris,
        I took help from ur link and i declared a global attribute request_number.
    and i created an event handler ON_ALV_INSERT and did the follwing coding for giving default value wen ever am inserting new row.
    FIELD-SYMBOLS: <wa_row> LIKE LINE OF r_param->t_inserted_rows.
      DATA bill_details TYPE REF TO zdom_bill_detail.
      LOOP AT r_param->t_inserted_rows ASSIGNING <wa_row>.
        bill_details ?= <wa_row>-r_value.
        IF bill_details->REQ_NUMBER IS INITIAL.
      DATA lo_nd_bill_detail TYPE REF TO if_wd_context_node.
      DATA lo_el_bill_detail TYPE REF TO if_wd_context_element.
      DATA ls_bill_detail TYPE wd_this->Element_bill_detail.
    navigate from <CONTEXT> to <BILL_DETAIL> via lead selection
      lo_nd_bill_detail = wd_context->get_child_node( name = wd_this->wdctx_bill_detail ).
    lo_el_bill_detail = lo_nd_bill_detail->get_element( index = <wa_row>-index ).
          lo_el_bill_detail->set_attribute(
            EXPORTING
              name  = 'REQ_NUMBER'
              value = wd_comp_controller->request_number
    Wen am  setting the value of wd_comp_controller->request_number to my context attribute am getting NULL object ref error.
    lo_el_bill_detail->set_attribute(
        name =  `REQ_NUMBER`
        value = wd_comp_controller->request_number ).
    Pls give some suggestions,
    Thanks in Advance,
    Nalla.B

  • Table which contains Start & End Destination details

    Hi All,
    I was trying to find out the table which contains the start and end destination details of a mileage claim in Travel Management.
    Can any one let me know the table names.
    Thanks and Regards
    Sri

    Hi Srinivas,
    Thanks for the reply!
    but what iam trying to find out is during mileage claim we usually enter the start destination and end destination . Now i wanted to know where will these details go and get stored as i need to amend some changes on the PDF form and i need to fetch these details to get them displayed.
    Thanks and Regards
    Sri

  • Table that contains the change date for every cost element

    Hi everyone!
    Can anyone please help me find a table which contains the change date for every cost element?
    Thanks,Jess

    If you basically want to find out if anyone changed the cost element, you need to use transaction KA05 and enter the cost element and controlling area.
    This would actually bring you whatever field was changed and on double clicking give you the actual change and the date on which the change was made.
    Problem is this change date is actually the creation date of a change document which is in the table CDHDR.Its not like the change date is on any master tables.
    Hope this helps
    Deepa

  • Table for Start and End time of Process Chain

    greetings experts,
    Hi All,
    I Have to give an Excel Sheet to Top level manager on Start and End Time of Data Load in each InfoPackage (PSA Load) triggered by Process Chain, please let me know if there is any table who keeps these information.
    Regards
    Sulochan

    Hi,
    You can use the program /SSA/BWT to give the Timings of the process Chain runs.
    1) To access this tool Goto SE38 .Type in u201C/SSA/BWTu201D as the Program name and click on execute. The list of all the tools that this Program contents are displayed.
    2) By default the option u2018Process Chain Analysisu2019 is selected. Now click on the execute button. Then you are displayed with the options through which you can select to perform analysis at Process Chain level or Process Type level. (Along with that, the Time Zones used to display the information is also displayed)
    3)If you click on the button u2018Process Chainsu2019 a window Pops up, here you need to provide the Chain-ID and/or the Log-ID and the Start Date/Time and the End Date/Time.
    4)Decide the parameters to enter as per your requirement, suppose your requirement is to check the runtime of a particular process chain for the past one week, then provide the technical name of that chain in the field Chain-ID and the start and end dates as per last one week and click on execute.
    5)Then the logs of the Process Chain for the selected dates are displayed along with the status (Red, Green or Yellow). The logs of the local chains (if any exist in the Process Chain selected) are also displayed (Much more additional information exist which is self explanatory). Now you can have a look at the Runtimes of different logs.
    Regards,
    Suprajah.

  • Adding primary key column in populated table

    Hi all,
    I am trying to add a column into a table which is already populated. The column which needs to be added has to be Primary Key.
    As expected, oracle popped up the error (ORA-01758) that, a NOT NULL column cannot be added unless the table is empty.
    One possibe way is to create a new temp table and then transfer all the current data...renaming the temp table later.
    Is there any other way to accomplish this task?
    Thanks

    Hello,
    As error suggested you cannot add a not null constraint on new column to table which is already populated. What else you can do beside you got fairly simple and quick idea of creating a temp table and moving data?
    You can add new column but null, update the column with the values and alter the table marking column as not null. But your idea of empty temp table is simple and quick one.
    CREATE TABLE my_objects
    AS
       SELECT 'my_new_column' my_new, owner
       FROM all_objects
       WHERE ROWNUM < 1;
    _Not Null_
    ALTER TABLE MY_OBJECTS
    MODIFY(MY_NEW  NOT NULL);
    _Primary key_
    ALTER TABLE MY_OBJECTS
    ADD CONSTRAINT MY_OBJECTS_PK
    PRIMARY KEY
    (MY_NEW);Regards

  • Optimise query on the table which contain 1000 column

    Hi ,
    I have query on the table which contain 1000 columns
    when i am executing query on same table .It is taking time .
    Select * from abc
    where col1 between start_date and end_date ;
    abc table contain 1000 columns.
    please tell me how to optimise query

    Yeah, that was my thought as well ... 1000 columns? wtf?
    I can't think of many reasons for why you'd need to do a select * on it, and the scenarios that would require that are better addressed at the DBA level, perhaps using db replication and the data pump, etc. So to start with try selecting just the data you would need.
    One thing you can do right off the bat is to partition that table by date, and also to analyze and run statistics on it (this was a nightly operation at my last job).
    You can also create a materialzed view that refreshes overnight, just on the slice of the data you need. Use a forced fast refresh to make it current before you use it.

  • Table  which stores the changes on a object

    Hi,
    Could any one tell me a table which stores the changes done to an object ex:Master data info object.
    I want to know when an particular attribute added to the master data.
    Thanks in advance

    I am not sure what is the level of detail you are looking for.
    CDHDR might help.
    Arun

  • Is there any standard SAP table which stores the license number assigned to a delivery item

    Hi Experts,
    This is in relation to license number assigned to a delivery item under ‘Export License Log’. Our scenario is for delivery of type NLCC created for an inter-company stock transport order. (i.e.not a sales order case where the license may get copied from sales order to delivery through copy control)
    As we understand, for legal control – relevant scenarios, export license for each item shall be determined afresh every time the delivery is accessed. (Depending on legal regulation, grouping, destination country, export control class, delivery partners vis-à-vis license master customer assignments etc.)
    To print the license text on one of the delivery output types, we want to access the license number for each item. (determined under export license log)
    Our question is:  is there any standard SAP table which stores the license number assigned to a delivery item?
    We have checked some of the license tables (T606*, VAEX, EMXX etc.) but couldn’t get any specific table storing delivery-item-specific license data.
    Helpful answers Text Removed
    Regards,
    Jagan
    Message was edited by: G Lakshmipathi
    Dont add such text in your post

    Hi Lakshmipathi,
    The export control log can be accessed by going to delivery Extras-> Export license log
    We need a table that stores the determined license for each item in a delivery document ( as shown in the below screenshot)
    Regards,
    Jagan

  • Table which stores the list of active ods objects in BW

    Hi,
    I am trying to find out the list of active ods objects starting with y and Z, Is there any table which has the information regarding that. For Infoobject I found the table as "RSDIOBJ". Can you plz let me know if there is any table for ods.
    Thank you in advance,
    Raghavendra Reddy BIjevemula

    Hi Raghu,
    u r typing it wrong..
    its "RSDODSO"..
    It will definitely work..
    which gives all available ODS.
    Regards-
    MM

  • Please help me to know the tables which contain details of APD and Open hub destination

    Hi experts,
    I need to know the list of APDs that have been created in our system. So can you please let me know the table name (if there is any) which contains the name of the APD and as well as the status (active / inactive) of the APD.
    Thanks ,
    Shalini

    Hi Shalini,
    Go to RSANWB  T-code and select any analysis process. Then press the "monitor" button. On the monitor screen, you can see the selection criteria in a table on the right. Now double-click on the table and a popup will come up where you can set the selection criteria. in particular, you can set the time frame and the analysis process selection.
    Hope it 'll help you..........
    Regards,
    Mukesh

Maybe you are looking for

  • How would I migrate OS 10.6 from my mac mini to my macbook running 10.5 ?

    How would I migrate OS 10.6 from my mac mini to my macbook running 10.5 ?  I eventually want to upgrade to 10.8.  Can I upgrade to 10.8 from 10.6 OS?  I recently purchased an iPhone 5.  I wanna use the iCloud.

  • HT1349 why i cant see my library content in my laptop?

    why i cant see my library content in my laptop?

  • Using broadband routers as simple access points?

    I need a simple Access Point and the WAP610N seems to be sufficient. However, I might like to get simultaneous dula-band capability, and it seems I must go to something like the WRT400N to get the. However, the WRT400N has a broadband connection. Can

  • Rotating shapes?

    Does anyone know how to make moving shapes in Adobe Premiere Pro? What I'm trying to do is making a square and have it rotate slowly e.g 90 degrees but stay in the same place (if that makes sense? lol) Thanks.

  • Mavericks Mail won't auto check

    I have Mail preferences set to check Mail every five minutes which it has done correctly forever. Just yesterday, I noticed it is no longer checking mail automatically. I have to check manually in order to retrieve new emails. (I have set and reset t