You are here: Re: SQL Server 2005 - SELECT query « MsSQL Server « IT news, forums, messages
Re: SQL Server 2005 - SELECT query

Posted by Bill on 10/18/06 13:46

Lionel,

I am making an assumption that you can return multiple rows to the user
to pick from. And that you want the exact match to appear as the most
relevant and first in the list.

SELECT 1 AS sort_order, row_data
FROM tbl
WHERE Description = 'input'
UNION
SELECT 2 AS sort_order, row_data
FROM tbl
WHERE Description like '%input%'
AND Description != 'input'
ORDER BY sort_order, ?

You can use multiple filters and unions to modify and rank the results
ie. WHERE DESCRIPTION like 'input%'
description like substring(input, 1, 10) + '%' --Not sure if this
works outside of a dynamically build query.


Lionel Pinkhard wrote:
> Hi
>
> I currently have a select query with "Description = 'input from user
> here'" which basically returns the associated row containing the
> Description field exactly as typed by the user, however, would it be
> possible to, if not found, return the closest match? I am using
> Microsoft Visual Studio 2005 with C# as language and Microsoft SQL
> Server 2005 as database.
>
> Regards,
>
> Lionel Pinkhard
>
>
>
> ---
> avast! Antivirus: Outbound message clean.
> Virus Database (VPS): 0642-0, 2006/10/17
> Tested on: 2006/10/18 12:46:07 PM
> avast! - copyright (c) 1988-2006 ALWIL Software.
> http://www.avast.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация