how i could take the longest no match??

  • a

  • Not very sure aboiut your inputs and output but try this...

    Declare @t1 Table(mid int, val varchar(100))

    Insert into @t1

    Select 1,'123' union all

    Select 2,'123456' union all

    Select 3,'123456789' union all

    Select 4,'123456789123'

    Declare @vChk varchar(100)

    Set @vChk = '123'

    Select Top 1 * from @t1

    where val like '%' + @vChk + '%'

    Order By Len(val) desc

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • Here is another way to do it using replace and len functions:

    Declare @t1 Table(mid int, val bigint)

    Insert into @t1

    Select 1,95 union all

    Select 2,959 union all

    Select 3,44 union all

    Select 4,959898

    declare @NewNum bigint

    set @NewNum = 9598989898954412

    select top 1 val

    from @t1

    order by LEN(REPLACE(convert(varchar(30),@NewNum),CONVERT(varchar(30),val),''))

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply