473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

tsql Substring question

I am trying to find a way to dynamically retrieve the substring
starting point of an nText field.

My query looks something like

SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT like
'claim%'"

This query has substring starting point set to 0. Is there a way to
determine the starting point based on the first occurrence of the
search term? If first occurrence of 'claim' is at 25th character then
the query should start substring at 25th and end at 225th character. I
am trying to avoid usage of UDF. Is there a way to handle this through
plain a SQL statement? Any help would be appreciated. TIA.

Jul 23 '05 #1
1 8077
On 11 Jan 2005 14:43:36 -0800, sy******@gmail.com wrote:
I am trying to find a way to dynamically retrieve the substring
starting point of an nText field.

My query looks something like

SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT like
'claim%'"

This query has substring starting point set to 0. Is there a way to
determine the starting point based on the first occurrence of the
search term? If first occurrence of 'claim' is at 25th character then
the query should start substring at 25th and end at 225th character. I
am trying to avoid usage of UDF. Is there a way to handle this through
plain a SQL statement? Any help would be appreciated. TIA.


Hi sysindex,

First, you should know that the numbering for SUBSTRING starts at 1 in SQL
Server, not at 0.

Second, with your WHERE clause, the search string will always start on
position 1. I assume you meant to write WHERE DocText LIKE '%claim%' (note
the extra %).

SELECT ID, SUBSTRING (DocText, CHARINDEX('claim', DocText), 200)
FROM MyTable
WHERE DocText LIKE '%claim%'
(untested)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve | last post by:
Hi; I'm brand spanking new to sqlserver ( nice so far ). I need to make a simple data change across a list of tables. Basically replace an old date with a new date. However, the people I am...
2
by: Steve | last post by:
Hi; I have been writing a lot of short tsql scripts to fix a lot of tiny database issues. I was wondering if a could make an array of strings in tsql that I could process in a loop, something...
18
by: mountain man | last post by:
Greetings to all database professionals and laymen, Let us make a bold assumption that we have developed a software tool for the SQL Server environment which simply acts as an interface between...
2
by: dynoweb | last post by:
I have several *.sql files with schema/data changes to be applied to our current database. Is there a way to create a TSQL script that could be run from the SQL Query Analyzer that would...
0
by: sysindex | last post by:
I am trying to find a way to dynamically retrieve the substring starting point of an nText field. My query looks something like, SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT...
1
by: TOM GUGGER | last post by:
OMNI GROUP tgugger@aimexec.com T-SQL/ CONTRACT TO PERM/ ATLANTA
7
by: Dana Shields | last post by:
I am attempting to upsize from access to SQL Server. I'm trying to convert my queries to SQL Server views; however, I'm having a lot of difficulty with the syntax differences. For instance, a...
3
by: David Lozzi | last post by:
Howdy, ISSUE 1: See issue 2 below. I have a distance calculator on my site which works great. However, the users need to sort by distance, which make sense. I'm not sure how to do it other than...
16
by: David Lozzi | last post by:
Hello, I have some code that adds a new user. The new user has a checkboxlist of items which they can be associated with. I would like to send this list of items to TSQL along with the new user...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.