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
 part of postcode

Author  Topic 

gagani
Posting Yak Master

112 Posts

Posted - 2012-04-03 : 07:07:04
For the input table

100 BD23 2DB
101 BD3 4ZX
102
103 AX2 43Z
104 SW19 4ZB

how to get part of the postcode(part before the space of the postcode) like this
100 BD23
101 BD3
102
103 AX2
104 SW19

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-03 : 07:34:58
[code]CASE
WHEN CHARINDEX(' ',Col2) > 0 THEN
LEFT(@x,CHARINDEX(' ',Col2)-1)
ELSE
Col2
END
[/code]This takes care of cases where there is no space as well.
Go to Top of Page
   

- Advertisement -