Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MS SQL:- Regular Expressions

Author  Topic 

stoneferry
Starting Member

3 Posts

Posted - 2008-06-24 : 07:18:22
Hi, the Microsoft SQL Server version is 2000


Basically I want use a basic regular expression but can't seem to get the syntax right.

i want to compare ID_short = ID_Long

ID_short is a truncated version of ID_Long, and I want to search on the beginning only (hence I can't use the 'LIKE' comparative on it's own).

What is the syntax to use Reg Expressions (or if anyone knows a non RegExp way of searching the beginning please let me know).



Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-24 : 07:22:23
Post some examples and maybe we can show you how LIKE works.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

stoneferry
Starting Member

3 Posts

Posted - 2008-06-24 : 07:39:53
Two example IDs:

ID_short- 2ACKMA
ID_long- 2ACKMAR

LIKE Cannot be used because of the potential presense of ACKMA2 ACKMAR2 etc.

So searching on the beginning of ID_Long is required using ID_Short as the criteria. The truncation of the ID_Short is due to technical circumstances beyond control at present.

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-24 : 07:50:08
Great! Now we got some sample data.
Now we only need to know what to compare with.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-24 : 07:52:45
try using condition
ON PATINDEX(ID_short+'%',ID_long)>0
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-24 : 08:07:30
or using LIKE

SELECT *
FROM Table
WHERE ID_Long LIKE ID_Short + '%'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -