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 2005 Forums
 Transact-SQL (2005)
 split string

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2009-09-07 : 08:22:25
Hi,

I have a sp that gets a parameter product_code that is in the format w22289-43juil.
I need to split the value into 2 other params: @product_color and @product_make
@Product_color in the string before the - and @product_make are the characters following the -.
How can i split the string and assign the parameters in the sp the correct values?

Thanks


Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-09-07 : 08:28:52
select substring(product_Code,1,charindex('-',product_code,1)-1),
substring(product_Code,charindex('-',product_code,1),len(product_Code)-charindex('-',product_code,1))

select left(product_Code,charindex('-',product_code,1)-1),
right(product_Code,charindex('-',reverse(product_code),1))
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-07 : 09:09:59
use this fnFilterString


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2009-09-07 : 10:44:15
Great thanks for the help :-)

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
Go to Top of Page
   

- Advertisement -