简体   繁体   中英

How to split a field into 10 new fields using Substring command in sql

I have a field that I title, nothing. As of yet it has no value. It is 261 characters at the end of my fixed width file, largefile. Now, I am being told to break this 261 character field into 10 separate fields. I can reimport it using this new schema. I found something else on this site I found something else on another site and it makes sense but it seems as if I am missing a few tidbits of code. Any thoughts on if I am going about this the right way?

I have tried the following code but ending in error.

update dbo.largefile 
set blank1 = substring(nothing,1,9)
unkn1 = substring(nothing,10,1)
unkn2 = substring(nothing,11,1)
blank2 = substring(nothing,12,35)
unkn3 = substring(nothing,47,4)
unkn4 = substring(nothing,51,1)
contact = substring(nothing,52,35)
title = substring(nothing,87,35)
contactphone = substring(nothing,122,10)
website = substring(nothing,132,204)
unkn5 = substring(nothing,203,59);

    Msg 102, Level 15, State 1, Line 3
    Incorrect syntax near 'unkn1'.

You are missing commas after each assignment:

update dbo.largefile 
set blank1 = substring(nothing,1,9),
unkn1 = substring(nothing,10,1),
unkn2 = substring(nothing,11,1),
blank2 = substring(nothing,12,35),
unkn3 = substring(nothing,47,4),
unkn4 = substring(nothing,51,1),
contact = substring(nothing,52,35),
title = substring(nothing,87,35),
contactphone = substring(nothing,122,10),
website = substring(nothing,132,204),
unkn5 = substring(nothing,203,59);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM