I adopted a script from a link belowTable is large enough (several tens of columns, but it seemsseveral hundreds of thousands rows), so it's desired to work with known columns. Cando it be done for an unknown number of columnsin single table scan (like SELECT *
doesif possible)? I mean.
I have multiple tables,appreciate any help and I really don't want to use dynamic SQL or write tens of stored proceduresany possibility to implement MergeTable1
achieve it without any bias, MergeTable2
SQLCLR, DSQL and so on, everything is applicable if it works fast and makes its job.
TableIn this example table is large enough (several tens ofsmall and has only 5 columns, several hundreds of thousands rows), so it's desiredbut in real table it will be much larger. I really want this script to work fast. I tried do it in singlemyself, but my script works for SQLSERVER2012+ so I deleted it as not applicable.
Numbers: table scancould have 150k of rows, 20 columns, 20-80k of unique (if possible).id
s and average SELECT COUNT(id) FROM T GROUP BY ID
is 2..5