Skip to content

Is it possible to recreate the raw SQL from the tokens? #127

Answered by bruce-dunwiddie
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

The intention would be yes.

Doing your replacement will be challenging on more complex SELECT statements using only TSQLToken's from TSQLTokenizer however, trying to keep track of if you're in the column list or not, especially considering CTE's.

The simplest way, if you still have the original SQL as a string, would be to use TSQLStatementReader to parse a TSQLSelectStatement. Then, you can look at the SELECT property, and its Tokens property, which would contain your column list, after a few keyword tokens like SELECT, TOP, DISTINCT. You might choose to drop some of those also. But once you find the first token that you want to start dropping, you can get it's BeginPosition , and replac…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by bruce-dunwiddie
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
1 participant