all groups > sql server new users > february 2007 >
You're in the

sql server new users

group:

Specific part from a field


Specific part from a field Dimitris Nikolakakis
2/21/2007 12:00:00 AM
sql server new users:
I have a table and one field is 'ItemCode' nvarchar 20.

The data in this field are like xxxxxxxxxx-xxxxxx

The '-' is not in a specific place in the data. I want to separate the two
parts of the field into two different fields, Code1 and Code2.

Is there any way using a stored procedure to do it?

Thanks
Dimtris

Re: Specific part from a field Hari Prasad
2/21/2007 6:39:42 AM
Hello,

Use can use CHARINDEX. See the below example. Change the table name XX3 and
column name Field1.

select

case when field1 like '%-%' then

left(field1,charindex('-',field1)-1) else field1 end firstfield1,

case when field1 like '%-%' then

right(field1,charindex('-',reverse(field1))-1) else '' end lastfield1

from xx3



THanks

Hari

[quoted text, click to view]

AddThis Social Bookmark Button