troubleshooting Question

Setting a DateTime value to NULL during Bulk Insert if substring is ""

Avatar of JD_Steele2
JD_Steele2 asked on
Microsoft SQL Server
2 Comments1 Solution723 ViewsLast Modified:
Hello,

I'm doing a bulk insert from a text file into a MS SQL database. My method is to read the entire line of each record of the text file into a one field 'temptable' (column name in that temp table is 'EligLine'). I then do an insert using SubStrings into the main folder (data is positional and not delimited). The problem I'm running into is that not ALL records have values in the ClaimantDOB position range. I'd like for these to be stored as 'NULL' in the main database table during the insert when they are blank.

Here's my INSERT Statement:
INSERT INTO TB1353Eligibility (ClaimNumber,ClaimantFN,ClaimantLN,DateLoss,ClaimantDOB,ClaimantSOJ,ClaimantSex,CovCode,Company,Office)
SELECT SUBSTRING(EligLine,1,20),SUBSTRING(EligLine,21,20),SUBSTRING(EligLine,41,20),SUBSTRING(EligLine,61,2)+'/'+SUBSTRING(EligLine,63,2)+'/'+SUBSTRING(EligLine,65,4),SUBSTRING(EligLine,69,2)+'/'+SUBSTRING(EligLine,71,2)+'/'+SUBSTRING(EligLine,73,4),SUBSTRING(EligLine,77,2),SUBSTRING(EligLine,79,1),SUBSTRING(EligLine,80,2),SUBSTRING(EligLine,82,3),SUBSTRING(EligLine,85,3)
FROM TB1353EligBulkWork

Let me know if more information is needed or if I need to explain my problem better.

Thanks!
ASKER CERTIFIED SOLUTION
D B
Database Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros