Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

hana - SQL Table Transformation - using an "if" statement in the "Select" command to split text in a column into their own rows

I have a source date table in this format:

Year  Mon1              Mon2      ...      Mon12
2025  1110001110001101  0010111010110110
2024  000111011011101   0101101110110101

This is the source table. This is a calendar table, and each "1 or 0" in the Month column represents a day, and 1 is for days worked and 0 is for days not worked for each year based off of the US holiday Calendar

I am looking to transform this table into the following Format, as seen in image 2

Year  Month   Day  Working day
2025  01      01   0
2025  01      02   1

For the entire table.

Does anybody know of any way to accomplish this?

This image is the source table

how the table needs to be transformed

question from:https://stackoverflow.com/questions/65862548/sql-table-transformation-using-an-if-statement-in-the-select-command-to-sp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Bottom Up Approach :

Step 1 : Form queries to extract individual Month Columns for a particular year

Step 2 : Apply Split_String SPLIT_TO_TABLE logic to convert columns to rows. Refer this link

Step 3 : Apply case statement for each of these column to row tables to identify if it is a working day or a non-working day.

Step 4 : Union All the result for every month.

Step 5 : Iterate this logic for all years.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...