Lately I’ve been using a lot of stringagg of a distinct list. Making it dynamic like how you showed will be another great tool in the bag. Thank you so much!
Brad: Your LinkedIn profile shows an impressive list of Microsoft certifications. When you have time, please do a video on what SQL Server certifications are still valid and worthwhile, and what to leave behind at this point in time - early 2023. Thanks.
Another great, incredibly helpful, easy to follow video - thank you! Question about STRING_AGG: I and my colleagues occasionally run into circumstances where the list it brings back is non-unique - i.e., there are duplicates in it, inexplicably; we cannot get STRING_AGG to work and must result to using STUFF (yuck). This doesn't seem to happen if it's used in a CTE or main query that calls data from a preceding CTE, (or apparently a derived table, like you use here). Is there a general rule of thumb for avoiding duplicates in the aggregated string when using STRING_AGG? (Perhaps you've covered this already in another video?)
You can just add the column list to the ORDER BY, ORDER BY CustomerId,' + @Columns or you can actually hard code some values if you only want to order by some of the columns
Brad, really appreciate you taking time and sharing your knowledge, your videos are really helpful.
No problem, glad that you find them useful.
What a relief! This is like going from straight drive to automatic. 😊
Lately I’ve been using a lot of stringagg of a distinct list. Making it dynamic like how you showed will be another great tool in the bag. Thank you so much!
Excellent.
Brad: Your LinkedIn profile shows an impressive list of Microsoft certifications.
When you have time, please do a video on what SQL Server certifications are still valid and worthwhile, and what to leave behind at this point in time - early 2023. Thanks.
I do need to do some videos on certifications, it's something I have invested a lot of time into.
Another great, incredibly helpful, easy to follow video - thank you! Question about STRING_AGG: I and my colleagues occasionally run into circumstances where the list it brings back is non-unique - i.e., there are duplicates in it, inexplicably; we cannot get STRING_AGG to work and must result to using STUFF (yuck). This doesn't seem to happen if it's used in a CTE or main query that calls data from a preceding CTE, (or apparently a derived table, like you use here). Is there a general rule of thumb for avoiding duplicates in the aggregated string when using STRING_AGG? (Perhaps you've covered this already in another video?)
Hi, you are correct, as far as I'm aware STRING_AGG will include duplicates and they need to be handled separately.
Hey Brad! Thank you for this. My code works, but now I want to save the result as a view. how do i do that?
Unfortunately you wouldn't be able to run this code within a View because it's a dynamic query, you need to use a Stored Procedure.
Can Null be removed from the output value. i have currently hardcoded IsNull along with cols name. Can we make dynamic query including IsNull??
I think it could work, you can't remove NULLs though, only replace.
thanks buddy!
How to order by the dynamic list of columns?
You can just add the column list to the ORDER BY, ORDER BY CustomerId,' + @Columns or you can actually hard code some values if you only want to order by some of the columns
very nice thanks u very much