Author |
Topic |
SimonG
Starting Member
15 Posts |
Posted - 2010-04-20 : 12:15:53
|
Hi all,New to DTS so bear with me.I have a table with a field contract number. I would like to parse the table and change the contract number value in the table (or write the value to another column) based on the numeric portion of the contract number For example the contract number may have the values C£0343, CW0343 and CW0343-01. I'd like to change these values to C0343.Is this possible?Thanks in advance.Simon |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-20 : 14:39:28
|
This looks like you just need an update statement and no dts or you should be more clear.To give an advice on the update statement we need more info about all possible values so we can see what rule will be good to change the data. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
SimonG
Starting Member
15 Posts |
Posted - 2010-04-20 : 17:07:30
|
Thanks for your post.The reason I have mentioned DTS is that I am exporting and transforming data from one DB to another using DTS and I would like this process to be part of that data export process.As far as I am aware the above values are the range of variation I will encounter.My post in the T-SQL forum (for which I was duly reprimanded by your goodself) was on the basis that I thought it might be possible to created a calculated column on the fly?Again thanks for your help.Regards,Simon |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-21 : 01:43:20
|
can you post what are the rules to be followed for convertion of contract number valueS?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
SimonG
Starting Member
15 Posts |
Posted - 2010-04-21 : 03:28:15
|
Thanks for the post.A little more detail;I'm using DTS to export to a table called contract sales with columns ContractNumber, Cost, TransactionDateOur contracts are split but all related sales cost has the rule that the numerical portion within the first six characters is always the same i.e. 0343 in my first post.the contract number format has three possible value formats;C0343 - if 5 chars strip first to give 0343C£0343 - if 6 chars strip first two to give 0343C$0343-01 - if > 6 chars strip first two and anything after sixth to give 0343I can then use the contract number field for further grouping etc.Hope this helps.Simon |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-21 : 04:24:27
|
[code]-- making testdatadeclare @test table (id int identity(1,1),ContractNumber varchar(255))insert @testselect 'C0343' union allselect 'C£0343' union allselect 'C$0343-01'select * from @test-- show solution using selectselectid,ContractNumber,case len(ContractNumber) when 5 then stuff(ContractNumber,1,1,'') when 6 then stuff(ContractNumber,1,2,'') else left(stuff(ContractNumber,1,2,''),4)end as NewContractNumberfrom @test--solution using updateupdate @testset ContractNumber=case len(ContractNumber) when 5 then stuff(ContractNumber,1,1,'') when 6 then stuff(ContractNumber,1,2,'') else left(stuff(ContractNumber,1,2,''),4) endwhere len(ContractNumber)>= 5-- show resultselect * from @test[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-21 : 05:42:09
|
Here is the solution by using a computed column:-- declare table with a computed columndeclare @test table(id int identity(1,1),ContractNumber varchar(255),ComputedContractNumber as (case len(ContractNumber) when 5 then stuff(ContractNumber,1,1,'') when 6 then stuff(ContractNumber,1,2,'') else left(stuff(ContractNumber,1,2,''),4) end)) -- insert test-datainsert @testselect 'C0343' union allselect 'C£0343' union allselect 'C$0343-01'-- see the resultselect * from @test No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
SimonG
Starting Member
15 Posts |
Posted - 2010-04-21 : 07:39:38
|
Webfred,Thanks very much for your guidance on this - most appreciated.Simon |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-21 : 07:58:24
|
welcome No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|