Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
wjohnson16
Starting Member
5 Posts |
Posted - 2009-11-09 : 16:32:57
|
| Data in the tableBoth Data Type nvarhcarid parent1 1/2/32 2/3/4what i am trying to get is 1=Father 2=Mother 3=Sister 4=Brother1 Father/Mother/Sister2 Mother/Sister/Brotherselect id, case Memberswhen 1 then 'Father'when 2 then 'Mother' end from testError Conversion failed when converting the nvarchar value '1\2\3' to data type int. |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-11-09 : 17:08:47
|
| Cast your numbers to char. for example when cast(1 as varchar(20)) then 'Father'. The problem is sql treats the values it finds in your case statement as the first data type it finds. So it sees 1 as an int and expects our then clause to provide it an int as well. It hits 'Father' and melts down. Casting to a varchar will get you around this.Mike"oh, that monkey is going to pay" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-10 : 03:16:21
|
| declare @t table(id int, parent varchar(100))insert into @tselect 1, '1/2/3' union allselect 2, '2/3/4'select id,parent,substring(new_parent,2,len(new_parent)-2) as new_parent from(select id,parent,replace(replace(replace(replace('/'+parent+'/','/1/','/Father/'),'/2/','/Mother/'),'/3/','/Sister/'),'/4/','/Brother/') as new_parentfrom @t) as tMadhivananFailing to plan is Planning to fail |
 |
|
|
wjohnson16
Starting Member
5 Posts |
Posted - 2009-11-13 : 15:16:47
|
| Thanks for you help |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-16 : 01:33:48
|
quote: Originally posted by wjohnson16 Thanks for you help
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|