February 6, 2012 at 8:21 am
I have a need to split an Address into to two columns based on the middle point of the columns byte size. The column is 50 byte's in size and I want to split the data in two with all the characters in the first 25 bytes being put in a new colomn (Address1) and all the characters in the second 25 bytes (Address2) into the second colomn. I have never heard of this before can it be done?
Thanks,
Sean
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
February 6, 2012 at 8:23 am
Use SUBSTRING
SELECT SUBSTRING(Address,1,25) AS AddressPart1,
SUBSTRING(Address,26,25) AS AddressPart2
FROM mytable
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537February 6, 2012 at 8:32 am
No offense but will the users consuming this data would be able to interpret it properly?
declare @str varchar(100) = 'Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved.'
SELECT SUBSTRING(@str,1,25) AS AddressPart1,
SUBSTRING(@str,26,25) AS AddressPart2
AddressPart1 AddressPart2
------------------------- -------------------------
Copyright © 2002-2012 Sim ple Talk Publishing. All
Please note the broken word ‘Simple’.
February 6, 2012 at 9:14 am
Great stuff. Thanks very much!
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply