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
 Select ?

Author  Topic 

oguzkaygun
Yak Posting Veteran

53 Posts

Posted - 2009-11-26 : 08:28:48
hello
i have records like below
100.01.001
100.01.002
100.01.003
ambrella01
ambrella10
ambrella1
ambrella2
ambrella3
i should get ambrella10 as result when i enter ambrella to textbox and click FindRecordButton. Secondly i should get 100.01.003 as result when i enter 100.01. to textbox.
My select query give me ambrella1 instead of ambrella10. but i get 100.01.003. What should i do to get true record for result ?
Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-26 : 08:32:11
What is the logic?
Why is ambrella10 and not ambrella1?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

oguzkaygun
Yak Posting Veteran

53 Posts

Posted - 2009-11-26 : 09:39:22
quote:
Originally posted by madhivanan

What is the logic?
Why is ambrella10 and not ambrella1?

Madhivanan

Failing to plan is Planning to fail


i should get max number about ambrella. ambrella1 is smallest than ambrella10.
Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-26 : 10:01:16
select top 1 col from your_table
where col like @col_value+'%'
order by replace(col,@col_value,'')*1 desc

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

oguzkaygun
Yak Posting Veteran

53 Posts

Posted - 2009-11-26 : 12:42:01
thank you for your reply.
it works perfect.
But i cant understand your code.
Can you explain your code ? especially replace(kod,@kod,'')*1
what does it do ?
Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-27 : 01:23:04
quote:
Originally posted by oguzkaygun

thank you for your reply.
it works perfect.
But i cant understand your code.
Can you explain your code ? especially replace(kod,@kod,'')*1
what does it do ?
Thanks


It removes the word from data and multiply the remianing part by 1 to make it as a number

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -