473,405 Members | 2,373 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,405 software developers and data experts.

PATINDEX and '[' character

Hi all

Using SQL Server 2000 SP3 on WIn2K Pro with SP2.

When I do this

SELECT PATINDEX('%[%', 'ABC[DEF')
GO

I get a result of 0, when I would expect a result of 4.

This works as I expect:

SELECT PATINDEX('%]%', 'ABC]DEF')
GO
I must be missing something really obvious here Any help would be
appreciated.
Jul 20 '05 #1
4 24535
John Winterbottom (jo***************@hotmail.com) writes:
Using SQL Server 2000 SP3 on WIn2K Pro with SP2.

When I do this

SELECT PATINDEX('%[%', 'ABC[DEF')
GO

I get a result of 0, when I would expect a result of 4.


[ is meta-character in wildcard expressions. You need this:

SELECT PATINDEX('%[[]%', 'ABC[DEF')
GO
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
The \ character is not an escape character until you define it as the
escape character. This is possible when using LIKE, but there is not
such ESCAPE clause in the PATINDEX syntax.

Therefore, you will need to resort to the second syntax, which is to
enclose it as the only character between square brackets.

SELECT PATINDEX('%[[]%', 'ABC[DEF')

Hope this helps,
Gert-Jan
John Winterbottom wrote:

"Joseph Weinstein" <jo*@bea.com> wrote in message
news:3F***************@bea.com...


John Winterbottom wrote:
Hi all

Using SQL Server 2000 SP3 on WIn2K Pro with SP2.

When I do this

SELECT PATINDEX('%[%', 'ABC[DEF')
GO

I get a result of 0, when I would expect a result of 4.

This works as I expect:

SELECT PATINDEX('%]%', 'ABC]DEF')
GO

I must be missing something really obvious here Any help would be
appreciated.


Hi. I think the '[' is syntactically significant, and is parsed out of the

input pattern,
just like the '%' is. Try escaping the '[' like this:

SELECT PATINDEX('%\[%', 'ABC[DEF')

This is just as if you wanted to search a pattern for the literal '%', you

would
have to escape that... Lemme know...
Joe


Thanks for the help Joe. Still doesn't work, even with the escape character.
Yes, i think you are right - it must be interpreting the '[' character and
stripping it out. If I come up with a fix I'll let you know.

Jul 20 '05 #3
"Gert-Jan Strik" <so***@toomuchspamalready.nl> wrote in message
news:3F***************@toomuchspamalready.nl...
The \ character is not an escape character until you define it as the
escape character. This is possible when using LIKE, but there is not
such ESCAPE clause in the PATINDEX syntax.

Therefore, you will need to resort to the second syntax, which is to
enclose it as the only character between square brackets.

SELECT PATINDEX('%[[]%', 'ABC[DEF')

Hope this helps,
Gert-Jan


Perfect - thank you.
Jul 20 '05 #4
"Erland Sommarskog" <so****@algonet.se> wrote in message
news:Xn**********************@127.0.0.1...
John Winterbottom (jo***************@hotmail.com) writes:
Using SQL Server 2000 SP3 on WIn2K Pro with SP2.

When I do this

SELECT PATINDEX('%[%', 'ABC[DEF')
GO

I get a result of 0, when I would expect a result of 4.


[ is meta-character in wildcard expressions. You need this:

SELECT PATINDEX('%[[]%', 'ABC[DEF')
GO

Thanks veyr much for your help. This works fine now.
Jul 20 '05 #5

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

Similar topics

10
by: M Bourgon | last post by:
I'm trying to figure out how to find the last whitespace character in a varchar string. To complicate things, it's not just spaces that I'm looking for, but certain ascii characters (otherwise,...
11
by: SQL_developer | last post by:
Hello, I am trying to update a column in a table with an 8 digit string. The 8 digit number is obtained from another column which is a comments field. e.g. Comments Field :
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
15
by: wizardyhnr | last post by:
i want to try ANSI C99's unicode fuctions. so i write a test program. the function is simple, but i cannot compile it with dev c++ 4.9.9.2 under windows xp sp2, since the compiler always think that...
2
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Can someone please tell me if there is an alternative to patindex in ASP.net. The reason why i need it is because, i want to create a textbox to let users enter lots of words and the words will...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
3
by: Phokojoe | last post by:
I have data items separated by commas (,) in several columns of a table in SQL database. When I use the substring and the patindex function, I get the error that 'Msg 536, Level 16, State 3, Line...
10
by: Paul W | last post by:
Hi all, I have an application that reads data in from a text file and stores it in a database. My problem is that there are some characters in the file that aren't being handled properly. For...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.