In a previous blog post, we looked at how to generate SQL using Biml. (If you haven’t read that post, you may want to start there and then come back here.) In this post, we will go through how to generate SELECT statements using the Biml column method GetColumnList.
Using Biml column methods
Biml column methods return code fragments. These code fragments can be used as building blocks to generate custom T-SQL statements. For example, the GetColumnList method returns a list of columns, separated by commas, that you can use in a SELECT statement. You can filter the columns and customize the output by passing parameters.
Examples of GetColumnList code fragments
If you have a table with three columns, the default output will look something like this:
[PersonID], [FirstName], [LastName]
But what if you don’t want to select all three columns? Or what if you want to use an alias for your table? No problem! The customized output can look something like this instead:
p.FirstName, p.LastName
We will go through the different ways of customizing the output a little later in this post.
Continue reading →