![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have an sql statement that needs to be executed of a list of parameters. say for example I have a table of Clients [LastName, Nationality] SELECT LastName, Nationality FROM Clients WHERE LastName LIKE %Mc% So this gives me a list of all people like McNeil, McKnight and their nationality. but what if I wanted to do this for another name like Mac or OB or OC Can I put a list of 'likes' in the SQL statement? SELECT LastName, Nationality FROM Clients WHERE LastName LIKE (%Mc%, %Mac%, %OB%, %OC%) ORDER BY LastName and order them by the Mc, Mac, OB, OC parameter... What does the syntax look like for this if it can be done? |
#3
| |||
| |||
|
|
I have an sql statement that needs to be executed of a list of parameters. say for example I have a table of Clients [LastName, Nationality] SELECT LastName, Nationality FROM Clients WHERE LastName LIKE %Mc% So this gives me a list of all people like McNeil, McKnight and their nationality. but what if I wanted to do this for another name like Mac or OB or OC Can I put a list of 'likes' in the SQL statement? SELECT LastName, Nationality FROM Clients WHERE LastName LIKE (%Mc%, %Mac%, %OB%, %OC%) ORDER BY LastName and order them by the Mc, Mac, OB, OC parameter... What does the syntax look like for this if it can be done? |
#4
| |||
| |||
|
|
On 23-02-11 18:48, SpreadTooThin wrote: I have an sql statement that needs to be executed of a list of parameters. say for example I have a table of Clients [LastName, Nationality] SELECT LastName, Nationality FROM Clients WHERE LastName LIKE %Mc% So this gives me a list of all people like McNeil, McKnight and their nationality. but what if I wanted to do this for another name like Mac or OB or OC Can I put a list of 'likes' in the SQL statement? SELECT LastName, Nationality FROM Clients WHERE LastName LIKE (%Mc%, %Mac%, %OB%, %OC%) ORDER BY LastName and order them by the Mc, Mac, OB, OC parameter... What does the syntax look like for this if it can be done? SELECT LastName, Nationality, 1 FROM Clients WHERE LastName LIKE %Mc% UNION SELECT LastName, Nationality, 2 FROM Clients WHERE LastName LIKE %Mac% UNION SELECT LastName, Nationality, 3 FROM Clients WHERE LastName LIKE %OB% UNION SELECT LastName, Nationality, 4 FROM Clients WHERE LastName LIKE %OC% ORDER BY 3, LastName -- Luuk |
#5
| |||
| |||
|
|
I have an sql statement that needs to be executed of a list of parameters. say for example I have a table of Clients [LastName, Nationality] SELECT LastName, Nationality FROM Clients WHERE LastName LIKE %Mc% So this gives me a list of all people like McNeil, McKnight and their nationality. as well as ones like "Smack" & "Bob" & "Rock" |
#6
| |||
| |||
|
|
On Feb 23, 11:20 am, Luuk <L... (AT) invalid (DOT) lan> wrote: On 23-02-11 18:48, SpreadTooThin wrote: I have an sql statement that needs to be executed of a list of parameters. say for example I have a table of Clients [LastName, Nationality] SELECT LastName, Nationality FROM Clients WHERE LastName LIKE %Mc% So this gives me a list of all people like McNeil, McKnight and their nationality. but what if I wanted to do this for another name like Mac or OB or OC Can I put a list of 'likes' in the SQL statement? SELECT LastName, Nationality FROM Clients WHERE LastName LIKE (%Mc%, %Mac%, %OB%, %OC%) ORDER BY LastName and order them by the Mc, Mac, OB, OC parameter... What does the syntax look like for this if it can be done? SELECT LastName, Nationality, 1 FROM Clients WHERE LastName LIKE %Mc% UNION SELECT LastName, Nationality, 2 FROM Clients WHERE LastName LIKE %Mac% UNION SELECT LastName, Nationality, 3 FROM Clients WHERE LastName LIKE %OB% UNION SELECT LastName, Nationality, 4 FROM Clients WHERE LastName LIKE %OC% ORDER BY 3, LastName -- Luuk Thanks Luuk. The 1, 2, 3, 4 that you added to the Select statement are constants that end up in the record set? If so, then what is the purpose of the 3 in the 'order by 3, Lastname'? |
#7
| |||
| |||
|
|
as well as ones like "Smack" & "Bob" & "Rock" |
#8
| |||
| |||
|
|
I have an sql statement that needs to be executed of a list of parameters. say for example I have a table of Clients [LastName, Nationality] SELECT LastName, Nationality FROM Clients WHERE LastName LIKE %Mc% So this gives me a list of all people like McNeil, McKnight and their nationality. but what if I wanted to do this for another name like Mac or OB or OC Can I put a list of 'likes' in the SQL statement? SELECT LastName, Nationality FROM Clients WHERE LastName LIKE (%Mc%, %Mac%, %OB%, %OC%) ORDER BY LastName and order them by the Mc, Mac, OB, OC parameter... What does the syntax look like for this if it can be done? |
#9
| |||
| |||
|
|
SpreadTooThin wrote: I have an sql statement that needs to be executed of a list of parameters. say for example I have a table of Clients [LastName, Nationality] SELECT LastName, Nationality FROM Clients WHERE LastName LIKE %Mc% So this gives me a list of all people like McNeil, McKnight and their nationality. but what if I wanted to do this for another name like Mac or OB or OC Can I put a list of 'likes' in the SQL statement? SELECT LastName, Nationality FROM Clients WHERE LastName LIKE (%Mc%, %Mac%, %OB%, %OC%) ORDER BY LastName and order them by the Mc, Mac, OB, OC parameter... What does the syntax look like for this if it can be done? SELECT LastName, Nationality FROM Clients WHERE LastName LIKE '%Mc%' OR LastName LIKE '%Mac%' OR LastName LIKE '%OB%' OR LastName LIKE '%OC%' ORDER BY LastName ASC If your programming/scripting language has support for it, you can store a soundex of the name and search by that. |
#10
| |||
| |||
|
|
as well as ones like "Smack" & "Bob" & "Rock" Sometime people take analogies toooo far... |
![]() |
| Thread Tools | |
| Display Modes | |
| |