473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(DO CTEXT,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 8111
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(DO CTEXT,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('clai m', 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
5482
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 doing it for want a program that produces logging of what it does.
2
11946
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 like array arrayListOfTablesToProcess = { "orders", "phone",
18
4628
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 an end-user in an organization and the database, through the exclusive use of stored procedures which are authored by the organization or by software developers. All development work at the application software level may thereby be conducted...
2
18706
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 sequentially call the *.sql files? i.e. call schemaVersionCheck.sql call addFieldToLoanTable.sql call updateLoanTrigger.sql
0
2700
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 like 'claim%'" This query has the 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
1
1729
by: TOM GUGGER | last post by:
OMNI GROUP tgugger@aimexec.com T-SQL/ CONTRACT TO PERM/ ATLANTA
7
17397
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 query with select mid(tblTable.FieldName,1,10)should look something like select substring(tblTable.FieldName,1,10). This is really the simplest of examples. I've tried using the SQL Server Import tool, but it takes the queries and changes them...
3
2544
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 like this. With the returning query include the distance from origin. Here's my dilemma, I have the script working great in VB which provides the distance, but that is not sortable, but when I port it over to TSQL I get differing results. Here is the...
16
5094
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 information. I would guess to combine the selected items like so: "6,4,8,19,2". Kind of do the following: INSERT into tblUser (fields) VALUES (data)
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.