Ok, I have a table that contains a number of columns, one of these columns contains a 'unitref' e.g.AC02/001D.
I import a new set of records, approx 7,000 per week in a DTS package from CSV Flat File into the table.
What I need to achieve at either the point of import of new data weekly, or once the new data is sitting in its final resting home, is a copy of the first two 2 Chars of the UnitRef, in the example above, this would make it 'AC' and then place that in a column named 'site_ref'.
Having posted the question on this forum relating to grabbing the first two chars of a value and placing them in a temporary table by utilising the Left(field,2) command in SQL (Kindly answered by CryptoKnight), I was wondering how I can do this possibly by using the inesrt into type command. I have many columns that get imported this is only a tiny step of many things that ideally would need to happen on an import,
Regards
You can update all that does not have a siteref set with something like this
update t
set siteref = left(t.unitref, 2)
from dbo.table t
where t.siteref is null and len(t.unitref) > 1;
This will find all records in table where siteref is not set and has a unitref with 2 or more characters (otherwise the left(, 2) will be illegal) and set it as the siteref for the row
EDIT: Might have misunderstood you...
No comments:
Post a Comment