Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need add a 1 to a column

Author  Topic 

2revup
Posting Yak Master

112 Posts

Posted - 2013-07-02 : 06:54:45
I have a CSV, which I am doing a bulk import on. To which I am creating a table see below for structure.

Is there anyway that I can some how append and create a new column, the column just needs to insert an INT of '1'

Is this even possible?


Create TABLE Shop_Import
(
Cat_name VARCHAR(max) NULL,
ProductID INT NULL,
Manufacture VARCHAR(max) NULL,
Product_Name VARCHAR(max) NULL,
QTY INT NULL,
Spare VARCHAR(max) NULL,
Gender VARCHAR(max) NULL,
Battery VARCHAR(10) NULL,
Min_Age VARCHAR(10) NULL,
Cost money NULL,
Age VARCHAR(40) NULL,
Gender_Selection VARCHAR(40) NULL,
Images VARCHAR(max) NULL,
Summary VARCHAR(max) NULL,
Description VARCHAR(max)NULL,
Weight [decimal](16, 2) NULL,
Height [decimal](16, 2) NULL,
Length [decimal](16, 2) NULL,
Width [decimal](16, 2) NULL
)
GO

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-02 : 07:05:37
if you're using BULKINSERT then what you need to do is add the column afterwards usinh

ALTER TABLE TABLE Shop_Import ADD ColumnName int NOT NULL DEFAULT 1


if you want to insert column also along with data you need to use

INSERT...
SELECT *
FROM OPENROWSET (....)


see OPENROWSET here

http://sqlmate.wordpress.com/2012/08/09/use-your-text-csv-files-in-your-queries-via-openrowset/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -