Solved

Help creating derived column in SSIS to remove trailing character and set column based on value

Posted on 2013-05-20
4
360 Views
Last Modified: 2016-02-10
Hi,

I have a CSV file which has a column that shows the Entity_ID for our CRM system, in the following format

"Entity Id","Entity Name"
"57468","The ABC Superannuation Fund"
"57468","The ABC Superannuation Fund"
"66180J","Fred & Wilma Flinstone (Joint)"
"66180J","Fred & Wilma Flinstone (Joint)"
"87866","Rubble Super Fund"
"87866","Rubble Super Fund"

What I need to do is create  two new columns based on the Entity ID column showing the numeric ID code and a column to indicate that it is a joint account.

Entity Id      Entity Name                                       Raw_EntityID     Joint_Account
57468      The ABC Superannuation Fund              57468                  N
57468      The ABC Superannuation Fund              57468                  N
66180J     Fred & Wilma Flinstone (Joint)                66180                  Y
66180J     Fred & Wilma Flinstone (Joint)                66180                  Y
87866      Rubble Super Fund                                  87866                  N
87866      Rubble Super Fund                                  87866                  N


Any ideas very much appreciated.
0
Comment
Question by:Steven Reid
  • 2
4 Comments
 
LVL 10

Expert Comment

by:HuaMinChen
ID: 39183140
Use
..
case when charindex('J',[entity Id])>0 then 'Y' else 'N' end as Joint_account
from table1
...
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39183260
and adding strip 'J' from entity

...
, replace([entity Id],'J','') as Raw_EntityID
, case when charindex('J',[entity Id])>0 then 'Y' else 'N' end as Joint_account
from table1
0
 

Author Comment

by:Steven Reid
ID: 39186208
Thanks Portlet Paul.
So you think that a new SQL task with this as an update or insert, is a better way compared to a Derived column?
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39186228
That would depend on may factors.

If you need Raw_EntityID & Joint_Account in many situations it might be more efficient to have those values stored instead of derived. Using an update is one approach.
OR
you could possibly add these as 'computed columns' to the table perhaps, and in this option you can have it 'persisted' as well
OR
create View that produces these derived columns that you can re-use instead of having to repeat the string manipulation code in query code.

The point is there are options but I don't know which suits you best.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question