@from parameter with "order by" deranges the commas
audacity76 opened this issue · comments
if you add a from parameter which includes a "order by" clause the commas are not set correctly. The first value row gets a comma and another row is missing the comma.
Problem occurs here: [https://github.com/readyroll/generate-sql-merge/blob/master/master.dbo.sp_generate_merge.sql#L480]
Unfortunately I don't seem to be able to reproduce the issue. This is the query I'm using:
EXEC AdventureWorks2017.dbo.sp_generate_merge 'CurrencyRate',
@schema = 'Sales',
@from = "FROM [Sales].[CurrencyRate] ORDER BY [FromCurrencyCode], [ToCurrencyCode], [ModifiedDate]"
If you're able to post some repro code that'd be great.
Ignore the previous comment, I managed to repro it with the following:
EXEC AdventureWorks2017.dbo.sp_generate_merge 'CurrencyRate',
@schema = 'Sales',
@from = "FROM [Sales].[CurrencyRate] ORDER BY [ToCurrencyCode] DESC"
The key element of reproducing the problem seems to be ensuring that a different first row is returned by the query, than would otherwise occur without an "order by" clause specified. In the above case, ORDER BY [ToCurrencyCode] DESC column
causes CurrencyRateID=13
to be returned first, whereas normally the result set would start with CurrencyRateID=1
.
@audacity76 I've got a fix ready to go in PR #52. If you have a chance to confirm that this resolves the issue for you, that'd be great!