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
 General SQL Server Forums
 New to SQL Server Programming
 combine column fields together into one field

Author  Topic 

rvan
Starting Member

28 Posts

Posted - 2007-01-24 : 19:42:39
Hello to All,

I needs help to combine these together but how would I eliminate necessarily zero in front of "PropertyHouseNumber".


Table: DirectHome

Column fields.......
PropertyHouseNumber, PropertyStreetDirection, PropertyStreetName, PropertyMODE

0000001091 , W , 000026TH , RD


Thank you


RV

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-24 : 19:47:09
[code]declare @s varchar(200)

select @s = '0000001091'

select @s, '_' + replace(ltrim(replace(@s, '0', ' ')), ' ', '0') + '_'[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-24 : 19:50:03
is PropertyHouseNumber only contain numeric ?

select convert(varchar(10), convert(bigint, PropertyHouseNumber))



KH

Go to Top of Page

rvan
Starting Member

28 Posts

Posted - 2007-01-25 : 11:33:54
quote:
Originally posted by khtan

is PropertyHouseNumber only contain numeric ?

select convert(varchar(10), convert(bigint, PropertyHouseNumber))



KH





Hi, KH

Data type for PropertyHouseNumber is contain Char only.


thank you

RV
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-01-25 : 12:04:18
So then your whole expression is going to be

SELECT replace(ltrim(replace(PropertyHouseNumber, '0', ' ')), ' ', '0') + ', ' + PropertyStreetDirection + ', ' + replace(ltrim(replace(PropertyStreetName, '0', ' ')), ' ', '0') + ', ' + PropertyMODE
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2007-01-26 : 10:04:45
Hi all,

Here's an alternative...

declare @s varchar(200)
select @s = '0000001091'
select substring(@s, patindex('%[^0]%', @s), 200)


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -