Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:42:21+00:00 2026-05-27T11:42:21+00:00

Hello SOF community: I have a table like this InvoicingActivityStartDay InvoicingActivityEndDay 27 26 27

  • 0

Hello SOF community:

I have a table like this

 InvoicingActivityStartDay InvoicingActivityEndDay
 27                        26
 27                        26
 01                        NULL --NULL MEANS LAST DAY OF MONTH
 01                        NULL
 15                        14    

I need a T-SQL query that will return the following for the data above, given the current date; if current date = 12-JAN-2012, the results should be as below

InvoicingActivityStartDATE               InvoicingActivityEndDATE
27-DEC-2011 12:00:00.000                 26-JAN-2012 23:59:99.999
27-DEC-2011 12:00:00.000                 26-JAN-2012 23:59:99.999
01-DEC-2011 12:00:00.000                 31-DEC-2011 23:59:99.999
01-DEC-2011 12:00:00.000                 31-DEC-2011 23:59:99.999
15-DEC-2011 12:00:00.000                 14-JAN-2012 23:59:99.999

Can you please show me how this be done in a single query?

Please note that if the start day is 1, that means the end day is always the last day of the previous month.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:42:21+00:00Added an answer on May 27, 2026 at 11:42 am

    If I interpret your requirements correctly (that the start day is that day of last month, and the end day is that day of this month; except when start day is 1), then you may want something like this (assuming your start/end days are integers; if not, cast them as ints):

    SELECT DATEADD(DAY,InvoicingActivityStartDay-1,
                    DATEADD(Month,DATEDIFF(Month,0,GETDATE())-1,0))
           AS [InvoicingActivityStartDATE] 
          ,CASE InvoicingActivityStartDay
          WHEN 1 THEN DATEADD(ms,-3,
                         DATEADD(Month,DATEDIFF(Month,0,GETDATE()),0))
          ELSE DATEADD(ms,-3,
                DATEADD(DAY,InvoicingActivityEndDay,
                        DATEADD(Month,DATEDIFF(Month,0,GETDATE()),0)))
          END AS [InvoicingActivityEndDATE] 
    FROM t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i got a batch file, something like this: if %day%==monday, tuesday, wednesday, thursday,
Hello I have a custom control. This custom control has it's DataContext set to
If I have a function like so: function foo(){ return array(hello => world); }
hello all i have one json object like {event1:{title:My birthday,start:12\/27\/2011 10:20 ,end:12\/27\/2011 00:00 },event2:{title:My
Hello I have this query... if (isset($_REQUEST['deletePost'])) { $q = $dbc -> prepare(DELETE FROM
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello can anybody solve this please I'm creating the object in the action class
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello I have two text inputs which get their values from a datepicker. What
Hello StackOverflow community, The air.swf file referenced here: http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_3.html used to launch AIR applications

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.