Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Like based on prefix table
Message
 
 
To
14/05/2013 10:08:02
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01573772
Message ID:
01573812
Views:
61
>I have a Prefix tables containing records with a Prefix field such as "AB", "KN", "LL" and "BB" as well as a Tag field such as "CM111", "CM222", "CM333" and "
>"CM444". I process a main table having a title such as "Abertimer". For each record of that table, I need to find the record in teh Prefix table so I can extract the Tag value. For example, in this case, it would be the one having a Prefix field "AB". This is because "Abertimer" starts with "AB". I am not sure about the syntax to use. The reason I ask is that I also have Prefix values having four letters. So, I cannot compare with the first two letters only. This is variable. Anyone would have an idea on how to do this?

Try
SELECT TOP (1) p.* FROM Prefixes p
    JOIN Master m ON m.title LIKE p.Prefix + '%'
  ORDER BY LEN(p.Prefix) DESC
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform