Skip to main content
Tweeted twitter.com/StackDBAs/status/695598088984141824
added 80 characters in body
Source Link

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 MergeTable1achieve it without any bias, MergeTable2SQLCLR, 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).ids and average SELECT COUNT(id) FROM T GROUP BY ID is 2..5

I adopted a script from a link below, but it seems to work with known columns. Can it be done for an unknown number of columns (like SELECT * does)? I mean I have multiple tables, and I really don't want to use dynamic SQL or write tens of stored procedures to implement MergeTable1, MergeTable2 and so on.

Table is large enough (several tens of columns, several hundreds of thousands rows), so it's desired to do it in single table scan (if possible).

Table is large enough (several tens of columns, several hundreds of thousands rows), so it's desired to do it in single table scan (if possible).

I appreciate any help and any possibility to achieve it without any bias, SQLCLR, DSQL and so on, everything is applicable if it works fast and makes its job.

In this example table is small and has only 5 columns, but in real table it will be much larger. I really want this script to work fast. I tried do it myself, but my script works for SQLSERVER2012+ so I deleted it as not applicable.

Numbers: table could have 150k of rows, 20 columns, 20-80k of unique ids and average SELECT COUNT(id) FROM T GROUP BY ID is 2..5

added 149 characters in body
Source Link

Table is large enough (several tens of columns, several hundreds of thousands rows), so it's desired to do it in single table scan (if possible).

Table is large enough (several tens of columns, several hundreds of thousands rows), so it's desired to do it in single table scan (if possible).

added 3 characters in body
Source Link
ypercubeᵀᴹ
  • 98.6k
  • 13
  • 215
  • 305

I adopted a script from a link below, but it seems to work with known rowscolumns. Can it be done for an unknown number of columns (like SELECT * does)? I mean I have multiple tables, and I really don't want to use dynamic SQL or write tens of stored procedures to implement MergeTable1, MergeTable2 and so on.

I adopted a script from a link below, but it seems to work with known rows. Can it be done for an unknown number of columns (like SELECT * does)? I mean I have multiple tables, and I really don't want to use dynamic SQL or write tens of stored procedures to implement MergeTable1, MergeTable2 and so on.

I adopted a script from a link below, but it seems to work with known columns. Can it be done for an unknown number of columns (like SELECT * does)? I mean I have multiple tables, and I really don't want to use dynamic SQL or write tens of stored procedures to implement MergeTable1, MergeTable2 and so on.

2008R2 doesn't have such functionality
Source Link
Loading
deleted 242 characters in body; edited tags
Source Link
Loading
added 27 characters in body
Source Link
ypercubeᵀᴹ
  • 98.6k
  • 13
  • 215
  • 305
Loading
added 1122 characters in body
Source Link
Loading
added 1420 characters in body
Source Link
Loading
Source Link
Loading