derived bucket from 4 different date fields

raj thadak 21 Reputation points
2020-10-22T16:10:17.33+00:00

Hi,

I have around 4 different columns with dates in it and these columns are string/varchar data types..

need to derive a column from these 4 fields call it as Bucket ..got stuck with converting the string as these columns has some text in it like ---------- ----- ----H which can be converted into some dummy date say 1900-01-01

based on Today's date - get the buckets into 7 days, 14 days, 21 days, 28 days, 28Over

look for each value in each field and derive is it 7 days from today, 14 days from today, Etc in one single column called bucket

---------- ----- ----H - this is what I see when I query In SQL server mgmt. studio but when I paste into excel it shown as #NAME? - any help please

MaintenanceWindow cycle1date MaintenanceWindow cycle3date MaintenanceWindow cycle2date MaintenanceWindow cycle4date

NAME? #NAME? #NAME? #NAME?

NAME? #NAME? #NAME? #NAME?

2018-06-04 12:00 6H 2018-08-06 12:00 6H 2018-06-04 12:00 6H 2018-09-03 12:00 6H
2018-06-04 12:00 6H 2018-08-06 12:00 6H 2018-06-04 12:00 6H 2018-09-03 12:00 6H
2019-12-07 00:00 4H 2020-06-06 00:00 4H 2019-12-07 00:00 4H 2020-09-05 00:00 4H
2020-10-10 13:00 6H 2020-12-12 13:00 6H 2020-10-10 13:00 6H 2021-01-09 13:00 6H
2020-12-12 08:00 8H 2021-06-12 08:00 8H 2020-12-12 08:00 8H 2021-09-11 08:00 8H
2020-10-25 04:00 6H 2020-12-27 04:00 6H 2020-10-25 04:00 6H 2021-01-24 04:00 6H
2019-12-11 14:00 4H 2020-06-10 14:00 4H 2019-12-11 14:00 4H 2020-09-09 14:00 4H
2019-03-06 14:00 4H 2019-09-11 14:00 4H 2019-03-06 14:00 4H 2019-12-11 14:00 4H
2020-06-13 08:00 4H 2020-12-12 08:00 4H 2020-06-13 08:00 4H 2021-03-13 08:00 4H
2017-10-29 08:00 6H 2017-12-24 08:00 6H 2017-10-29 08:00 6H 2018-01-28 08:00 6H

NAME? #NAME? #NAME? #NAME?

NAME? #NAME? #NAME? #NAME?

2019-01-11 00:00 8H 2019-07-12 00:00 8H 2019-01-11 00:00 8H 2019-10-11 00:00 8H

NAME? #NAME? #NAME? #NAME?

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,666 questions
{count} votes

Accepted answer
  1. EchoLiu-MSFT 14,591 Reputation points
    2020-10-23T01:58:51.777+00:00

    Hi @raj thadak ,

    Welcome to the Q&A sql server transact sql forum!
    It looks like you are posting a question on the QA forum for the first time, unfortunately we don’t understand your question and the result you want.

    As suggested by other experts, when you post a problem, please share with us the tables and insert data involved, and the output you expect (it can be images or excel data, etc.) so that the problem can be solved quickly.

    If you have any question, please feel free to let me know.
    If the response is helpful, please click "Accept Answer" and upvote it.

    Regards
    Echo


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.