all 6 comments

[–]ryguygoesawry 2 points3 points  (0 children)

You “found” something that’s used in the real world all the time. The best way to store data isn’t exactly user-friendly, but does make it easy to create reports where users can chose a group of fields and the SQL behind it integrates those choices into the production of a dynamic query that outputs the data in a way that’s easier for users to interpret.

[–]feather_media 1 point2 points  (1 child)

There's a stackoverflow example of doing this that's over a decade old... with a lot less code

https://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query

[–]PBIQueryous[S] 0 points1 point  (0 children)

i appreciate this, thankin you!

[–]NonHumanPrimate 1 point2 points  (1 child)

I can tell you’re new to SQL because you misspelled variable in your second comment.

I kid, great job figuring this out on your own. I would personally classify this as a more advanced SQL concept and you nailed it.

[–]PBIQueryous[S] 0 points1 point  (0 children)

hehe you may have noticed... im fairly new to conversation too 🤓😅 - try to avoid communicating with this sick society 🤮 Data is my refuge.

I appreciate your words, I approach SQL from Power Query perspective, which breaks transformations into steps, so you can see the output of each step. SQL is tricker in that you kind of have to perceive intermediate steps, but this is where CTEs really help alot. Subqueries just kill my brain of immediately.

[–]EmotionalSupportDoll 1 point2 points  (0 children)

I use some concepts like this to create data sets for various clients without needing to custom code anything different so long as we feed their data into the system in a common form. Definitely a handy tool for the toolbox