I need to run three queries and end up with one recordset (to be used via ADO.Net in an ASP.Net page).
If I leave out the Order By clauses, this returns the data I need but not in the order I need it.
Here is what I am trying to accomplish:
I want a record set with all the data from these three select queries but it needs to be ordered in the following way.
First all records where the last name is equal to the input name (in this case Adams).
Second, all records where the last name starts with the first three letters of the input name but not any records found in the first query.
Third, all records where the last name has the input name anywhere in the name except the records found in the first two queries.
How can I write the sql or stored procedure to accomplish this? I am using SQL Server 2000.
Thanks,
Gabe
Code:
(select * from employee_email where LName = 'adams' order by LName, FName
union
select * from employee_email where LName like 'ada%'
and LName <> 'adams' order by LName, FName)
union
(select * from employee_email where LName like '%adams%'
and LName <> 'adams' and LName not like 'ada%'
order by LName, FName)
Here is what I am trying to accomplish:
I want a record set with all the data from these three select queries but it needs to be ordered in the following way.
First all records where the last name is equal to the input name (in this case Adams).
Second, all records where the last name starts with the first three letters of the input name but not any records found in the first query.
Third, all records where the last name has the input name anywhere in the name except the records found in the first two queries.
How can I write the sql or stored procedure to accomplish this? I am using SQL Server 2000.
Thanks,
Gabe