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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 padding

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-05-16 : 07:26:06
hi
i have the following 3 lines in a column (example 3 lines)


'Net Asset Value per share for Ignis Absolute Return Government Bond Fund. Class A EUR Distribution Hedged'
'Net Asset Value for Ignis Absolute Return Government Bond Fund. Class I2 GBP'
Total Outstanding shares Class I2 GBP'

is there a way to pad this out so from where is says class to the end are always the same length.

i need to read class on word so i can insert just that into another column

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-05-16 : 07:56:21
this?
declare @test1 varchar(255) = 'Net Asset Value per share for Ignis Absolute Return Government Bond Fund. Class A EUR Distribution Hedged'

select
case
when charindex('Class',@test1) > 0
then substring(@test1, charindex('Class',@test1)+6,len(@test1)-charindex('Class',@test1))
else 'not found'
end





Too old to Rock'n'Roll too young to die.
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-05-16 : 08:54:04
sorry should have said these are all ready in a coulnm in a tbale so want to just pull it from there or pad it there
there will be different lines with different text dont want to have to declare them all
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-05-16 : 09:10:16
i set my column to 255
used this code

select
case
when charindex('Class',[Group]) > 0
then substring([Group], charindex('Class',[Group])+0,len([Group])-charindex('Class',[Group]))
else 'not found'
end
from dbo.BNYWorkingTempNavTable



still coming out different lengths
any ideas why
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-05-16 : 10:03:41
sorteed

select
case
when charindex('Class',[Group]) > 0
then substring([Group], charindex('Class',[Group])+0,len([Group])-charindex('Class',[Group])+1)

end
from dbo.BNYWorkingTempNavTable
Go to Top of Page
   

- Advertisement -