how to search data using "like" in sql server -


i typed word "boat", need records start boat , contains "boat".but starting "boat" must appear first

i tried following

select   asicccodeid,asiccdescription                  asicccodemaster  c                 c.asiccdescription 'boat%' or c.asiccdescription '%boat%' 

and

select a.* (   select   asicccodeid,asiccdescription                   asicccodemaster  c               c.isactive = 1  , (goodfor = 'm' or goodfor = 'b')  , c.asiccdescription 'unmilled%'     union   select   asicccodeid,asiccdescription                   asicccodemaster  c               c.isactive = 1  , (goodfor = 'm' or goodfor = 'b')  , c.asiccdescription '%unmilled%'     )a 

but gives me

4137    combustion boats  6360    boat, fibre 6361    boat, rubber - motorized 6362    boat, wooden canal boats 6363    boat, wooden engine 6370    wooden boats body building 6374    boat, rowing / sports 6375    boat, rubber - nonmotorized 6376    boat, wooden without engine-others 6379    parts of ships, boats etc., n.e.c 6391    ships, boats & other vessels, n.e.c 6394    ships, boats & other vessels, n.e.c 

i need records starts "boat" first , records contains "boat"

use case statement in order clause

select   asicccodeid,asiccdescription                  asicccodemaster  c                 c.asiccdescription '%boat%' order case when c.asiccdescription 'boat%' 0 else 1 end, c.asiccdescription 

since want titles start 'boat' appear first, case statement prioritize first. looks @ each record and, if description starts 'boat', assigns sort value of 0, otherwise assigns sort value of 1. order sorts ascending default, put 0s (the ones start 'boat') before 1s (the remaining records)


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -