Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substitute and replace functions

Status
Not open for further replies.

MARKNLA2

Technical User
Feb 28, 2002
15
0
0
US
how do i use the substitute and replace functions from the query design grid? can the be used as expressions in the field row or criteria row? what about within an update or append query?

marknla2
 
You can use functions in the Field, Criteria and Update To rows of the designer grid. You can use functions in SELECT, UPDATE, MAKE TABLE and APPEND (INSERT) queries.

NOTE: The replace function isn't recognized in a Jet Query. However, you can create a public user defined function to wrap around the Replace function.

User Defined Replace Function:

Public Function fnReplace _
(sString As String, sFind As String, _
sReplace As String) As String

fnReplace = Replace(sString, sFind, sReplace)

End Function

Select Example: Replace any occurrence of Tom with Jerry

Select
EmpName,
fnReplace(EmpName, "Tom", "Jerry")
From tblEmployees
Where Instr(EmpName, "Tom") > 0

Update Example: Update SSN replacing dashes with an empty string and converting employee name to proper case (using StrConv).

Update tblEmployees
Set SSN=fnReplace(SSN, "-", ""),
EmpName=strConv(EmpName, 3)

Criteria Example: Suppose tblEmployees has dashes in the SSN and tblTemp does not have dashes. Further, suppose you want to find which rows in tblEmployees exist in tblTemp.

Select * From tblEmployees
Where fnReplace(SSN, "-", "")
In (Select SSN From tblTemp) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top