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?
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.