﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / T-sql select - like / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 05:45:20 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>[quote][b]jarid.lawson (10/8/2012)[/b][hr][quote][b]ScottPletcher (10/8/2012)[/b][hr][code="sql"]SELECT lastnameFROM HR.EmployeesWHERE    lastname LIKE '%[/]%' AND    lastname NOT LIKE '%[/]%[/]%'[/code][/quote]Still have to add the line that removes / in the first character. I also believe you would want to remove any where / was the last character...[code="sql"]And Left(Ltrim(LastName), 1) &amp;lt;&amp;gt; '/'And Right(Rtrim(LastName),1) &amp;lt;&amp;gt; '/'[/code]I'm curious if this would not be a good option from an execution plan perspective? Are there better / faster ways of completing this?[/quote]Oops, I didn't initially read down far enough to see the new requirement of not a leading /:[code="sql"]SELECT lastnameFROM HR.EmployeesWHERE    lastname LIKE '[^/]%[/]%' AND    lastname NOT LIKE '[^/]%[/]%[/]%'[/code][/quote]In theory this could potentially be faster with a covering index on lastname (probably likely, if you plan on running this query very often), whereas the queries using REPLACE(...) or any other function on the lastname column would require a full table scan.  That is, "lastname [NOT] like" is SARGable but "&amp;lt;function&amp;gt;(... lastname ...)" is not.</description><pubDate>Mon, 08 Oct 2012 14:47:19 GMT</pubDate><dc:creator>ScottPletcher</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>[quote][b]ScottPletcher (10/8/2012)[/b][hr][code="sql"]SELECT lastnameFROM HR.EmployeesWHERE    lastname LIKE '%[/]%' AND    lastname NOT LIKE '%[/]%[/]%'[/code][/quote]Still have to add the line that removes / in the first character. I also believe you would want to remove any where / was the last character...[code="sql"]And Left(Ltrim(LastName), 1) &amp;lt;&amp;gt; '/'And Right(Rtrim(LastName),1) &amp;lt;&amp;gt; '/'[/code]I'm curious if this would not be a good option from an execution plan perspective? Are there better / faster ways of completing this?</description><pubDate>Mon, 08 Oct 2012 14:11:58 GMT</pubDate><dc:creator>jarid.lawson</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>[code="sql"]SELECT lastnameFROM HR.EmployeesWHERE    lastname LIKE '%[/]%' AND    lastname NOT LIKE '%[/]%[/]%'[/code]</description><pubDate>Mon, 08 Oct 2012 10:26:47 GMT</pubDate><dc:creator>ScottPletcher</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>Thank you all for the samples, dwain.c I utilized your excerpt and it worked for me. I appreciate everyone's help!</description><pubDate>Mon, 08 Oct 2012 09:10:52 GMT</pubDate><dc:creator>ggarcia 73023</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>[quote][b]CELKO (10/5/2012)[/b][hr]You are not just new to the forums, but have never read anything about RDBMS. [/quote]Backoff the new guy, Joe.  You don't know if he created the denormalized data or not.  Even if he did, that's not teaching and there's no need for that kind of comment.[quote]What you have is an attempt at a variant record in several different 1950's threu 1970's file systems.[/quote]BWAA-HAAA!!! You always say stuff like that but aren't you still using a 1950s push-stack to convert Adjacency Lists to Nested Sets?[quote]If you do nto care about being a good SQL programmer, there are several kludges for splitting this string into separate values.[/quote] Once again, you're totally out of line with such a comment.  Good programmers will, in fact, use some of the "kludges" to normalize the data if they're allowed and to simply use the data if they're not.  Heh... and it's not nearly as bad as the push-stack kludge. ;-)</description><pubDate>Sat, 06 Oct 2012 13:17:48 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>[quote][b]gravitysucks (10/5/2012)[/b][hr]AND SUBSTRING(LastName,1,1)&amp;lt;&amp;gt;'/' ---??[/quote]Yes or:[code="sql"]AND LEFT(LTRIM(LastName), 1) &amp;lt;&amp;gt; '/'[/code]The LTRIM is in case there are blanks only leading up to the slash.</description><pubDate>Fri, 05 Oct 2012 20:07:42 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>&amp;gt;&amp;gt; On the table I'm attempting to query there is a column called lastname that holds multiple last names for customers. Rows that have more than one last name are separated by a '/' character, no spaces are between the '/' and the last names. &amp;lt;,You are not just new to the forums, but have never read anything about RDBMS. A column is by definition, a scalar value. This is part of First Normal Form (1NF) and it is usually covered in the first 3-4 chapters of any book on the topic. What you have is an attempt at a variant record in several different 1950's threu 1970's file systems.If you do nto care about being a good SQL programmer, there are several kludges for splitting this string into separate values. I want to select customers with two last names, for instance customers like 'garcia/fish' or 'johnson-howard/bobby-ray'. </description><pubDate>Fri, 05 Oct 2012 17:50:39 GMT</pubDate><dc:creator>CELKO</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>AND SUBSTRING(LastName,1,1)&amp;lt;&amp;gt;'/' ---??</description><pubDate>Fri, 05 Oct 2012 16:40:57 GMT</pubDate><dc:creator>gravitysucks</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>Thank you both for the help, dwain I've used your example for getting the column information. It works great however it returns rows that begin with a '/' too which isn't exactly what I want. Is there a way to query only the last names with at least one character (letter or number) before the '/'? For example, last names like 'e/johnson' but not names like '/johnson'.</description><pubDate>Fri, 05 Oct 2012 15:16:58 GMT</pubDate><dc:creator>ggarcia 73023</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>Here's another way:[code="sql"]WHERE LEN(LastName) - 1 = LEN(REPLACE(LastName, '/', ''))[/code]</description><pubDate>Thu, 04 Oct 2012 18:21:11 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>Chain your charindexes.Basically, you'll want a where clause that looks like this:[code="sql"]WHERE	CHARINDEX( LastName, '/') &amp;gt; 0 -- / exists	AND CHARINDEX( LastName, '/', CHARINDEX( LastName, '/') + 1) = 0 -- No second /s[/code]I'll avoid discussing how much the design decision there makes me cringe...  it's very denormalized.</description><pubDate>Thu, 04 Oct 2012 16:09:14 GMT</pubDate><dc:creator>Evil Kraig F</dc:creator></item><item><title>T-sql select - like</title><link>http://www.sqlservercentral.com/Forums/Topic1368762-392-1.aspx</link><description>Hello,I'm new to these forums &amp; need some help putting together a T-SQL query for selecting some info from my db. On the table I'm attempting to query there is a column called lastname that holds multiple last names for customers. Rows that have more than one last name are separated by a '/' character, no spaces are between the '/' and the last names.I want to select customers with two last names, for instance customers like 'garcia/fish' or 'johnson-howard/bobby-ray'. Is there a way to select only rows that have one '/' entered in the character string? I don't want last names like 'davis/cameron/lew'. Oh, forgot to mention that the column is of type nvarchar. I assume that something like:select lastnamefrom HR.Employeeswhere lastname LIKE '[/]';would select entries that have '/'s however I'm not getting any results &amp; I need ONLY rows that have one '/'Hope this makes sense, I realize it's a pretty vague example however I'd be extremely grateful if anyone here can help me.</description><pubDate>Thu, 04 Oct 2012 16:05:05 GMT</pubDate><dc:creator>ggarcia 73023</dc:creator></item></channel></rss>