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)
 case statement

Author  Topic 

sqlhelp14
Yak Posting Veteran

55 Posts

Posted - 2009-01-21 : 11:33:07
i have 4 different types of values in subject field - (text datatype)

order item # KT-025
order item # 2921
order item # KT-017_01
order item # 01-456

i have query like -

select subject, substring(subject,Charindex('order item #',subject)+12,7) as order_number
from orders
where orderid = 'ord'

so i am getting the first row as a result - order item # KT-025
but not other 3rows - values...i know i have to use case statement for that so i can get all 4rows...how can i use case statement in this query?

any help would be appreciated.

thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-21 : 11:36:19
what are values of orderid field for them?
Go to Top of Page

sqlhelp14
Yak Posting Veteran

55 Posts

Posted - 2009-01-21 : 11:54:31
values are like -
KT-025 (-6 digit starting with alphabet)
2921 (-4 digit)
KT-017_01 (-9digit)
01-456 (-6digit but number)

means i want the values whatever comes after 'order item #' [whether its 4digit or 9digit or 6digit)..here its getting the correct result but only first row i m getting not other rows..

thanks for your reply.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-21 : 11:56:44
i'm asking about orderid value not subject
Go to Top of Page

sqlhelp14
Yak Posting Veteran

55 Posts

Posted - 2009-01-21 : 11:58:18
all fields orderid ='ord'
Go to Top of Page
   

- Advertisement -