New answers tagged bcp
BCP works fine. First, you create the target table. Then export data with the select and filter you need. Import data with BCP will fit the correct partitions. I did this before. I was on SQL 2014, but it will be fine on 2012.
The problem with using UNION to include the column names is that column names are strings but the fields in the unioned query are not necessarily strings (as you discovered with that error posted in the Question). And you cannot convert names into other types such as INT, DECIMAL, MONEY, DATETIME, etc. I did not have to provide any cast/convert when I ...
Presumably you are expecting the .csv file to be opened using Excel or some equivalent. I'd recommend wrapping the outputted text columns in double-quotes, such as: declare @sql VARCHAR(1000); Select @sql = 'bcp.exe "SELECT ''"userid"'',''"name"'',''"data"'', ''"data1"'',''"data2"'' UNION ALL SELECT CHAR(34) + CAST([userid] As VARCHAR(MAX)) + CHAR(34) , ...
Top 50 recent answers are included