Writing code to generate TSql using the ScriptDom is hard. There is a seemingly bewildering array of objects you can use and where you use different types is unclear, I think this is due to the complexity of the task, it really isn't simple and dealing with t-sql gets complicated very quickly - to be clear the ScriptDom is a great tool and although is difficult to use is 1 million times better than writing custom parsers / generators for t-sql.
To help I have written the ScriptDom visualizer which parses some t-sql and produces a tree of the different objects and properties that the ScriptDom needs for you to generate the same query via the ScriptDom rather than via text.
The ScriptDom is cool as it lets us generate valid t-sql as well as parsing t-sql, modifying and re-generating it so we can start to build our own tools to help sql developers - wahoo.
If you have no need to use the ScriptDom then this is a useless tool, if you need to interact with the ScriptDom in any way and you need to know what properties and types to use then this will be useful for you.
I have written it for me to use but am sure others will find it useful, it is as always on github, if you want to change anything just submit a pull request.
Look ma, pretty colours
Grab it from: