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)
 charindex query

Author  Topic 

khusiie
Yak Posting Veteran

78 Posts

Posted - 2009-01-15 : 14:52:50
select charindex('15425','order number #15425') - returns 15
and i want output - 15425

means i have 30 rows -
select orderid, charindex('Order number #',ordnum) as ord from orders will returns 30 different values.. in ord column...i want to use case statement in it

like -

select orderid, case when charindex('Order number #',ordnum) then [value after '#' sign and the length of that values are 7 ]


what should come after then ?

it should be return value whatever it will be there after '#' sign - 7digit...

output will be

orderid ord
--------------
100 1253245
123 415-512
124 15-1521

any idea?
thanks.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-15 : 15:10:42
Do you mean this?

Select orderid,substring(ordnum,Charindex('#',ordnum)+1,7)as ord from table
Go to Top of Page

khusiie
Yak Posting Veteran

78 Posts

Posted - 2009-01-15 : 15:15:00
excellent!!!!!!!!!

thanks a ton!!! i appreciate it!!!! Thanks
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-15 : 15:36:54
You are welcome
Go to Top of Page
   

- Advertisement -