﻿<?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)  / SUBSTRING Question? / 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 12:53:47 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SUBSTRING Question?</title><link>http://www.sqlservercentral.com/Forums/Topic1077681-392-1.aspx</link><description>Thanks Sean! I was able to use datalength and it works successfully now. Thanks for everyone's help!</description><pubDate>Mon, 14 Mar 2011 07:49:57 GMT</pubDate><dc:creator>dustin.walker</dc:creator></item><item><title>RE: SUBSTRING Question?</title><link>http://www.sqlservercentral.com/Forums/Topic1077681-392-1.aspx</link><description>Also check that mdmpa.message_text does not have non space chars following "ALL MET ITEMS FOR VIN PROCESSED SUCCESSFULLY"</description><pubDate>Mon, 14 Mar 2011 07:41:51 GMT</pubDate><dc:creator>David Burrows</dc:creator></item><item><title>RE: SUBSTRING Question?</title><link>http://www.sqlservercentral.com/Forums/Topic1077681-392-1.aspx</link><description>[quote]I think the issue is on "SUBSTRING(bd.buft_string_1, 35, 70) = mdmpa.message_text"[/quote]Did you prove this by removing the join and getting rows returned?If it is the substring then the most likely cause is either bd.buft_string_1 contains non space chars (hidden or otherwise) after "ALL MET ITEMS FOR VIN PROCESSED SUCCESSFULLY" or the text does not start at column 35.What is the size of bd.buft_string_1?</description><pubDate>Mon, 14 Mar 2011 07:39:40 GMT</pubDate><dc:creator>David Burrows</dc:creator></item><item><title>RE: SUBSTRING Question?</title><link>http://www.sqlservercentral.com/Forums/Topic1077681-392-1.aspx</link><description>Try using datalength instead of a hardcoded length. Think that should get you the desired result.</description><pubDate>Mon, 14 Mar 2011 07:38:31 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>SUBSTRING Question?</title><link>http://www.sqlservercentral.com/Forums/Topic1077681-392-1.aspx</link><description>Can someone please help! I'm having an issue with a query. It's using a SUBSTRING but I think there's a problem with it. It returns 0 rows when it should return 1. Here is the query in question.		SELECT v.veh_id, vi.inventory_id, SUBSTRING(bd.buft_string_1, 35, 70), bd.*		FROM buft_chrysler_data AS bd			INNER JOIN vehicle AS v WITH (NOLOCK)				ON SUBSTRING(bd.buft_string_1, 14, 17) = v.vin            INNER JOIN vehicle_inventory AS vi WITH (NOLOCK)                ON v.veh_id = vi.veh_id                    AND vi.own_dtm = (SELECT MAX(o.own_dtm)                            FROM ownership AS o WITH (NOLOCK)                            WHERE o.veh_id = v.veh_id                                AND o.tran_account_id = 1) -- Chrysler            INNER JOIN message_dcx_met_part_audit AS mdmpa WITH (NOLOCK)					--ON LTRIM(RTRIM(SUBSTRING(bd.buft_string_1, 35, 70))) = LTRIM(RTRIM(mdmpa.message_text))   					ON SUBSTRING(bd.buft_string_1, 35, 70) = mdmpa.message_text                           WHERE bd.tran_event_id = 62139I think the issue is on "SUBSTRING(bd.buft_string_1, 35, 70) = mdmpa.message_text". The mdmpa.message_text field is a varchar(70), this is why we're using 70 as our Substring length. However, it doesn't seem to like this. It should match where message_text is equal to "ALL MET ITEMS FOR VIN PROCESSED SUCCESSFULLY". If I simply use "SUBSTRING(bd.buft_string_1, 35, 44) instead where 44 is the exact length of the string it works just fine. How do I account for a varchar field though?Any help would be greatly appreciated!</description><pubDate>Mon, 14 Mar 2011 07:13:28 GMT</pubDate><dc:creator>dustin.walker</dc:creator></item></channel></rss>