Snapshot yearly to snapshot quarterly

Nhu Nguyen Ngoc Quynh 20 Reputation points
2023-04-03T05:14:33.66+00:00

Hello All,

I have a data table as below which has Date as yearly.

Data
339253126_1122171699177237_7687842927632488746_n

Required solution

338912488_210745208318091_735515779804858839_n

Now my requirement is I need to create a query to create quarterly data from the yearly data (by duplicating the yearly data details for each ID)
As I have 12 months data here i need to show 4 quarters data.

Could any one please help how to do? Thank you so much.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,895 questions
0 comments No comments
{count} votes

Accepted answer
  1. CosmogHong-MSFT 23,716 Reputation points Microsoft Vendor
    2023-04-03T05:52:30.27+00:00

    Hi @Nhu Nguyen Ngoc Quynh

    Please check this query:

    create table #data ([Date] int,ID int ,Field1 varchar(10),Field2 varchar(10),Field3 varchar(10))
    insert into #data values
    (201912,111,null,'A','A'),(202012,111,'B',null,'B'),(202212,111,'C','C','C'),
    (202212,222,'A','A','A')
    
    SELECT CONCAT(LEFT([Date],4),[Quarter])AS Year_Quarter,ID,Field1,Field2,Field3
    FROM #data CROSS APPLY (VALUES('03'),('06'),('09'),('12'))C([Quarter])
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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