|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Like Query And Null ValuesI have a table on SQL Server where one column allows Null values (docMName)
and I'm trying to perform a like query using one parameter. When executed the query fails to include rows with Null values for the docMName column. Is there a way to include these missing rows? Any help would be greatly appreciated. SELECT docIndex, docLName, docFName, docMName FROM tblStaffPhysicians WHERE (docFName + ' ' + docMName + ' ' + docLName LIKE '%' + ? + '%') Try:
SELECT docIndex, docLName, docFName, docMName FROM tblStaffPhysicians WHERE (docFName + ' ' + ISNULL (docMName, '') + ' ' + docLName LIKE '%' + ? + '%') -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA SQL Server MVP Columnist, SQL Server Professional Toronto, ON Canada www.pinpub.com .. "Rich" <R***@discussions.microsoft.com> wrote in message I have a table on SQL Server where one column allows Null values (docMName)news:829D8B3B-1E5D-4002-8D73-D9A563FC1B0D@microsoft.com... and I'm trying to perform a like query using one parameter. When executed the query fails to include rows with Null values for the docMName column. Is there a way to include these missing rows? Any help would be greatly appreciated. SELECT docIndex, docLName, docFName, docMName FROM tblStaffPhysicians WHERE (docFName + ' ' + docMName + ' ' + docLName LIKE '%' + ? + '%') Tom, thanks so much you are dead on target.
Show quote "Tom Moreau" wrote: > Try: > > SELECT docIndex, docLName, docFName, docMName > FROM tblStaffPhysicians > WHERE (docFName + ' ' + ISNULL (docMName, '') + ' ' + docLName LIKE '%' + ? > + '%') > > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA > SQL Server MVP > Columnist, SQL Server Professional > Toronto, ON Canada > www.pinpub.com > .. > "Rich" <R***@discussions.microsoft.com> wrote in message > news:829D8B3B-1E5D-4002-8D73-D9A563FC1B0D@microsoft.com... > I have a table on SQL Server where one column allows Null values (docMName) > and I'm trying to perform a like query using one parameter. When executed > the > query fails to include rows with Null values for the docMName column. Is > there a way to include these missing rows? Any help would be greatly > appreciated. > > SELECT docIndex, docLName, docFName, docMName > FROM tblStaffPhysicians > WHERE (docFName + ' ' + docMName + ' ' + docLName LIKE '%' + ? + '%') > >
Other interesting topics
|
|||||||||||||||||||||||