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.
| Author |
Topic |
|
TJ
Posting Yak Master
201 Posts |
Posted - 2002-08-30 : 12:34:58
|
Does anyone know if there is an SQL function/statement/code that does the same thing as the vbTextCompare?Thanks!TeresaThis will require more coding when I am able to recognize the '<' and the '&' in the string! Edited by - TJ on 09/06/2002 11:16:09 |
|
|
Onamuji
Aged Yak Warrior
504 Posts |
Posted - 2002-08-30 : 13:17:39
|
| SELECT 'HeLlO wOrLd!' = 'hElLo WoRlD!' AS TextCompare -- this is trueCAST('HeLlO wOrLd!' AS VARBINARY) = CAST('hElLo WoRlD!' AS VARBINARY) AS BinaryCompare -- this is falseThis help? |
 |
|
|
TJ
Posting Yak Master
201 Posts |
Posted - 2002-08-30 : 13:42:25
|
quote: SELECT 'HeLlO wOrLd!' = 'hElLo WoRlD!' AS TextCompare -- this is trueCAST('HeLlO wOrLd!' AS VARBINARY) = CAST('hElLo WoRlD!' AS VARBINARY) AS BinaryCompare -- this is falseThis help?
hmmmmm?? I tried running this in SQL 7 Query Analyzer and it does not work. Am I doing something incorrectly?I'm trying to find a function that replaces vbTextCompare that will search through a string and find extraneous characters such as '<', split the string into left & right. Place the characters to the left into one column and the characters to the right into another. The vb function I have does other comparisons as well that I will need to account for.Here's a small sample of the vb function I have:'*******Get Name Without JR, SR, III, IIII****************** NameExt = Right$(FullName, 3) If NameExt = "<IV" Or NameExt = "<JR" Or _ NameExt = "<SR" Or NameExt = "<II" Then FullName = Left(FullName, NameLen - 3) End If NameExt = Right(FullName, 4) If NameExt2 = "<III" Then FullName = Left(FullName, NameLen - 4) End If '***Find out How Many <s are in Name************************** LessThan1 = InStr(1, FullName, "<", vbTextCompare) LessThan2 = InStr(LessThan1 + 1, FullName, "<", vbTextCompare) If LessThan2 > 0 Then HowManyLess = 2 Else HowManyLess = 1 End If Depending on the answer to these questions, I decide where to parse the string, etc.Any ideas?Thanks again!Teresa |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-08-30 : 14:26:03
|
| vbTextCompare isn't a case sensitive mode, is it?You can do all this stuff with CharIndex or PatIndex functions...Jay White{0} |
 |
|
|
Onamuji
Aged Yak Warrior
504 Posts |
Posted - 2002-08-30 : 14:31:58
|
| Here's your code converted to T-SQL ... --*******Get Name Without JR, SR, III, IIII******************SET @NameExt = RIGHT(@FullName, 3)IF NameExt IN ("<IV", "<JR", "<SRC", "<II") SET @FullName = LEFT(@FullName, @NameLen - 3)SET @NameExt = RIGHT(@FullName, 4)IF @NameExt2 = '<III' SET @FullName = LEFT(@FullName, @NameLen - 4)--***Find out How Many <s are in Name**************************SET @LessThan1 = CHARINDEX(@FullName, '<')SET @LessThan2 = CHARINDEX(@FullName, '<', @LessThan1 + 1)IF @LessThan2 > 0 SET @HowManyLess = 2ELSE SET @HowManyLess = 1on a side note ... your vbTextCompare does nothing special in your vb code and is pretty much just extra space being used up.... |
 |
|
|
TJ
Posting Yak Master
201 Posts |
Posted - 2002-08-30 : 15:31:30
|
quote: vbTextCompare isn't a case sensitive mode, is it?You can do all this stuff with CharIndex or PatIndex functions...Jay White{0}
I don't think it is case sensitive. But I converted my string to UCASE before I hit this routine. Thanks for the info! Teresa |
 |
|
|
TJ
Posting Yak Master
201 Posts |
Posted - 2002-08-30 : 15:32:31
|
quote: Here's your code converted to T-SQL ... --*******Get Name Without JR, SR, III, IIII******************SET @NameExt = RIGHT(@FullName, 3)IF NameExt IN ("<IV", "<JR", "<SRC", "<II") SET @FullName = LEFT(@FullName, @NameLen - 3)SET @NameExt = RIGHT(@FullName, 4)IF @NameExt2 = '<III' SET @FullName = LEFT(@FullName, @NameLen - 4)--***Find out How Many <s are in Name**************************SET @LessThan1 = CHARINDEX(@FullName, '<')SET @LessThan2 = CHARINDEX(@FullName, '<', @LessThan1 + 1)IF @LessThan2 > 0 SET @HowManyLess = 2ELSE SET @HowManyLess = 1on a side note ... your vbTextCompare does nothing special in your vb code and is pretty much just extra space being used up....
Thanks for your help with this! I appreciate your time!Teresa |
 |
|
|
TJ
Posting Yak Master
201 Posts |
Posted - 2002-09-06 : 11:08:30
|
I was finally able to get back to writing this sproc and have more questions.Here is one of the strings I need to parse (there are 15 variations I will need to code for):CARL A<JONES<& ANGIE MYER Here is the code I have so far: DECLARE @NAMEEXT AS CHAR(3), @NAMEEXT2 AS CHAR(4), @LESSTHAN1 INT, @LESSTHAN2 INT, @HOWMANYLESS INT, @FULLNAME AS CHAR(60), @NAMELEN INT, @LT AS CHAR(3), @AMP INT, @HOWMANYAMP INT, @PRIMLNAME AS CHAR (30), @LFTCARET CHAR(1), @PRIMFNAME CHAR(25), @HELP AS CHAR (30)SET @FULLNAME = 'CARL A<JONES<& ANGIE MYER'SET @LFTCARET = '<'SET @LT = '<'SELECT REPLACE(@FULLNAME, @LT, '<')SET @NAMELEN = LEN(@FULLNAME)--*******Get Name Without JR, SR, III, IIII****************** SET @NameExt = RIGHT(@FullName, 3) IF @NameExt IN ("<IV", "<JR", "<SRC", "<II") SET @FullName = LEFT(@FullName, @NameLen - 3) SET @NameExt = RIGHT(@FullName, 4) IF @NameExt2 = '<III' SET @FullName = LEFT(@FullName, @NameLen - 4) --***Find out How Many <s are in Name************************** SET @LessThan1 = CHARINDEX(@FullName, '<', 1) SET @LessThan2 = CHARINDEX(@FullName, '<', @LessThan1 + 1) IF @LessThan2 > 0 SET @HowManyLess = 2 ELSE SET @HowManyLess = 1 --***Find out how many &s are in Name*******************************************SET @AMP = CHARINDEX(@FULLNAME, '&', 1)IF @AMP = 0 SET @HOWMANYAMP = 0ELSE SET @HOWMANYAMP = 1--***SET VARIABLE NAMES = NAMEL1 ***********************************************IF @HOWMANYLESS = 1 AND @HOWMANYAMP = 0 SET @PRIMLNAME = RIGHT(RTRIM(@FULLNAME), LEN(@FULLNAME) -(CHARINDEX('<', @FULLNAME))-@LESSTHAN1) SET @PRIMFNAME = LEFT(RTRIM(@FULLNAME), CHARINDEX('<', @FULLNAME)-1)IF @HOWMANYLESS = 1 AND @HOWMANYAMP = 1 SET @PRIMLNAME = RIGHT(RTRIM(@FULLNAME), LEN(@FULLNAME) -(CHARINDEX('<', @FULLNAME))) SET @PRIMFNAME = LEFT(RTRIM(@FULLNAME), CHARINDEX('<', @FULLNAME)-1) The return values are incorrect: CARL A<JONES<& ANGIE MYER(1 row(s) affected)HOW MANY < = 1HOW MANY & = 0THE FULL NAME IS = CARL A<JONES<& ANGIE MYER THE LAST NAME IS = JONES<& ANGIE MYER THE FIRST NAME IS = CARL A THE NEW NAME IS = CARL A JONES<& ANGIE MYER If I'm looking at the code correctly, it's only finding the first instance of the '<' and no instances of the '&'. Any suggestions and/or guidance would be greatly welcomed!Thanks!Teresa |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2002-09-07 : 14:15:27
|
| /*Not knowing all the variations mentioned I have attempted toprovide some code for the previously mentioned inputIt is not complete but I Hope this is of some help*/DECLARE @InString varchar(1000)SET @Instring = 'CARL A<JONES<& ANGIE MYER'DECLARE @MidPosition tinyint, @FoundLessThanCt int, @FoundAmpCt int, @FoundFirstName tinyint, @FirstName varchar(20), @LastSpacePosition int, @LastName varchar(30)SET @FoundLessThanCt = 0SET @FoundAmpCt = 0SET @FoundFirstName = 0SET @Firstname = ''SET @MidPosition = 0 SET @LastSpacePosition = 0WHILE ( @MidPosition < LEN(@InString) + 1 ) BEGIN --Count '<' IF SUBSTRING(@InString,@MidPosition,1) = '<' BEGIN SET @FoundLessThanCt = @FoundLessThanCt + 1 END --Count '&' IF SUBSTRING(@InString,@MidPosition,1) = '&' BEGIN SET @FoundAmpCt = @FoundAmpCt + 1 END --Get First Name IF ( @FoundFirstName = 0 AND @MidPosition > 1 ) BEGIN IF SUBSTRING(@InString,@MidPosition,1) = ' ' BEGIN SET @FirstName = LEFT(@InString,@MidPosition) SET @FoundFirstName = 1 END END --Get last name space IF SUBSTRING(@InString,@MidPosition,1) = ' ' BEGIN SET @LastSpacePosition = @MidPosition END SET @MidPosition = @MidPosition + 1END --Get Last NameSET @LastName = RTRIM(LTRIM(SUBSTRING(@Instring,@LastSpacePosition,LEN(@Instring))))SELECT @Instring as 'OriginalName', REPLACE(@InString,'<',' ') as 'NewName', @FirstName as 'Firstname', @FoundAmpCt as 'AmpCount', @FoundLessThanCt as 'LessThanCount', @LastName as 'LastName' |
 |
|
|
TJ
Posting Yak Master
201 Posts |
Posted - 2002-09-18 : 11:26:29
|
quote: It is not complete but I Hope this is of some help
It was of great help! THANK YOU! It worked as I thought it should. After implementing it, I was told that I need to return 4 variables after reading in one. So I've been working on revising it. Here is the code I have so far.Test data: 1)JOHN M<BROWN 2)HENRY A<CARTER 3)FRANK N<DE PORTA 4)FLORENCE E<JONES 5)JAMES R<ODONNELL 6) LILLIE B<OWEN-SMITH DECLARE @InString varchar(35) SET @Instring = 'FLORENCE E<JONES' DECLARE @MidPosition tinyint, @AmpCt int, @LastSpace int, @Less1 int, @Less2 int, @Amp1 int,@CharPos int, @TmpName varchar(35), @char varchar(1), @Kind varchar(1),@PLName varchar(20), @PFName varchar(15), @SLName varchar(20), @SFName varchar(15)SET @MidPosition = 0 SET @AmpCt = 0 SET @LastSpace = 0 set @less1 = 0 set @less2 = 0 set @amp1 = 0 set @CharPos = 0 SET @TMPNAME = '' SET @CHAR = '' SET @KIND = ''SET @PLNAME = '' SET @PFNAME = '' SET @SLNAME = '' SET @SFNAME = '' --get the field positions for the '<' and the '&' and set the appropriate variablesWHILE @MidPosition < LEN(@InString)begin set @char = SUBSTRING(@Instring,@midposition,LEN(@Instring)) if @char = '<'and @less1 = 0 begin set @less1 = @midposition set @kind = @char print "The first < is located in position: " + cast(@less1 as varchar) end if @char = '<' and @midposition > @less1 and @less2 = 0 begin set @less2 = @midposition print "The second < is located in position: " + cast(@less2 as varchar) end if @char = '&' begin set @amp1 = @midposition print "The & is located in position: " + cast(@amp1 as varchar) end IF SUBSTRING(@InString,@MidPosition,1) = ' ' BEGIN SET @LastSpace = @MidPosition END set @midposition = @midposition + 1end --ONE '<' AND ZERO '&'if @LESS1 <> 0 AND @less2 = 0 and @amp1 = 0begin if @lastspace < @less1 begin set @PLName = right(@instring, len(@instring) - @less1) set @PFName = left(@instring, (@less1 -1)) set @SLName = '' set @SFName = '' print "Stopped at 1st if!" end if @lastspace > @less1 begin set @PLName = right(@instring, len(@instring) - @less1) set @PFName = left(@instring, (@less1 -1)) set @SLName = '' set @SFName = '' print "Stopped at 2nd if!" endendprint @kindprint "@LESS1 = " + CAST(@less1 AS VARCHAR)print "@LESS2 = " + CAST(@LESS2 AS VARCHAR)print "@AMP1 = " + CAST(@Amp1 AS VARCHAR)PRINT "@LASTSPACE = " + CAST(@LASTSPACE AS VARCHAR)PRINT "FLORENCE E<JONES"print "PRIM LAST NAME IS: " + @PLNamePrint "PRIM FIRST NAME IS: " + @PFNamePrint "SEC LAST NAME IS: " + @SLNamePrint "SEC FIRST NAME IS: " + @SFName The procedure works NOW! Thanks for your help!TeresaEdited by - TJ on 09/18/2002 12:47:23 |
 |
|
|
|
|
|
|
|