![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I want a user to be able to search for names in a table of clients using a single parameter, but be eable to use "and" or "or" IN the parameter. Like this: @NameSearch nvarchar(100) AS DECLARE @PartA nvarchar(100), @PartB nvarchar(100) CASE When @nameSearch Like '%' + ' OR ' + '%' SELECT @PartA =(how do I get what's to the left of "OR" or "AND") SELECT @PartB (how do I get what's to the right of "OR" or "AND") SELECT c.UniqueID, c.LastName FROM dbo.tblClients c WHERE c.LastName = @PartA OR c.LastName = @PartB CASE ELSE SELECT c.UniqueID, c.LastName FROM dbo.tblClients c WHERE c.LastName = @NameSearch |
#3
| |||
| |||
|
|
You could probably use a combination of string parsing and dynamic SQL to do this, but for more complicated cases it would quickly become very difficult to maintain and secure. Or you could pass the names as a list, and use a technique like this: |
#4
| |||
| |||
|
|
I want a user to be able to search for names in a table of clients using a single parameter, but be eable to use "and" or "or" IN the parameter. Like this: @NameSearch nvarchar(100) AS DECLARE @PartA nvarchar(100), @PartB nvarchar(100) CASE When @nameSearch Like '%' + ' OR ' + '%' SELECT @PartA =(how do I get what's to the left of "OR" or "AND") SELECT @PartB (how do I get what's to the right of "OR" or "AND") |
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
|
INSERT INTO Candidates VALUES ('Larry', 'Perl'); --winner |
#9
| |||
| |||
|
|
Just thinking further on this, not to get too complicated, how would one go about creating a stored procedure where the client side looked like this: ClientName LIKE "Smith" AND/OR City IS "London" AND/OR Pet LIKE "Spot" etc... Where the user enters the quoted criteria and then selects AND or OR and LIKE or IS |
#10
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |