Even though I'm a beginner DB programmer I already noticed there are many large joins I find myself repeating over and over. I was thinking of just creating a table-valued function for commonly used joins, and allow a parameter to be passed into this function which will filter the results.
Eg. Instead of writing
SELECT *
FROM T1 join T2 on T1.A = T2.A
join T3 on T2.B = T3.B
join T4 on T3.C = T4.D
WHERE T1.D = '15' AND T2.D = '20' AND T3.C = '12'
I would write
SELECT *
FROM dbo.SOME_FUNCTION(' T1.D = '15' AND T2.D = '20' AND T3.C = '12' ')
My question is simply this. Is this something I should be attempting to do? Or am I ridiculously lazy for wanting to do this?
Have been trying to research/write this function all day, and have had many/many problems doing so. I know eventually, I can/will make it work, just wondering if it is worth my time.