sql server 2008 - add column while copying data in sql -
I am using SqlBulkCopy extensively in some records in another table from one table. To query the query, query is using a SqlDataReader. A difference between the tables (except the column order, which is handled in the mapping) is that there is a date column in the destination table in which the current date should be added. This date is not in the source table The current process code looks like this:
SqlCommand cmd = new SqlCommand ("select * from Dbo.source", cn); SqlDataReader rdr = cmd.ExecuteReader (); (Using SqlBulkCopy copy = new SqlBulkCopy (cn)) {copy.ColumnMappings.Add (0, 0); Copy. Column Mapping Add (1, 2); Copy. Column Mapping Add (3, 3); Copy. Column Mapping Add (2, 4); Copy Column Mapping Add (5, 5); Copy Column Mapping Add (14, 6); Copy.DestinationTableName = "Destination"; Copy.WriteToServer (RDR); }
DB SQL 2008 is ENT.
You can just select it from your SELECT:
SELECT * To return as GETDATE (), add dbo.source to CurrentDate
and then just add another column mapping.
Comments
Post a Comment