I am trying to insert into my table using bcp format file. But after insert the columns with default value is not getting inserted.
But when I run insert statement directly on the sql server, it takes the default value.
my table: MarginFeed
CREATE TABLE MarginFeed(
id BIGINT NOT NULL IDENTITY,
SMCP VARCHAR(50),
adtv NUMERIC(23,4),
adtvPeriod VARCHAR(8),
marketCap NUMERIC(23,4),
shortInt NUMERIC(23,4),
activeInd VARCHAR(5) DEFAULT 'R',
enteredDate DATETIME DEFAULT GETDATE(),
lastUpdatedDate DATETIME
);
the text file only has data for SMCP , adtv, adtvPeriod, marketCap, shortInt :
text file: Feed.txt
SMCP|ADV|ADVPeriod|MarketCapInUsd|ShortInterest
102982306|23068.76666666|90|29820313.20000000|
103656446|6167435.98888888|90|12318467.90720000|
format file: FeedFormat.Fmt
12.0
5
1 SYBCHAR 0 50 "|" 2 SMCP ""
2 SYBCHAR 0 54 "|" 3 adtv ""
3 SYBCHAR 0 8 "|" 4 adtvPeriod ""
4 SYBCHAR 0 54 "|" 5 marketCap ""
5 SYBCHAR 0 54 "\n" 6 shortInt ""
after bcp table value:
id SMCP adtv adtvPeriod marketCap shortInt activeInd enteredDate lastUpdatedDate
1 102982306 23068.7666 90 29820313.2000 (null) 2020-11-10 19:53:15 (null)
2 103656446 6167435.9888 90 12318467.9072 (null) 2020-11-10 19:53:15 (null)
The value of column 'activeInd' is defaulted to 'R' in create statement but it is blank after bcp IN using format file.
But when I run below on SQL Server Studio directly, i get the expected result.
INSERT INTO MarginFeed(SMCP, adtv, adtvPeriod, marketCap, shortInt)
VALUES ('102982306', 23068.76666666, '90', 29820313.20000000, null),
('103656446', 6167435.98888888, '90', 29820313.20000000, null);
Result:
id SMCP adtv adtvPeriod marketCap shortInt activeInd enteredDate lastUpdatedDate
1 102982306 23068.7667 90 29820313.2000 (null) R 2020-11-10 20:36:22 (null)
2 103656446 6167435.9889 90 29820313.2000 (null) R 2020-11-10 20:36:22 (null)
activeInd = R after direct insert.
Please help why it not working when using bcp.
Below bcp command I am using:
freebcp $table in $file -f$FormatFile $conStr -I$SQL_INTERFACES -t$DELIMETER -b$bnum -e$error