views:

18

answers:

2

I want to produce an alphabetized list of names produced by adding together two columns of names, columnA, and columnB.

I have tried this:

<cfquery name="listAuthors" datasource="hhLibrary">
SELECT title, (a1_Fname + a2_Fname) AS ColumnA, (a1_Lname + a2_Lname) AS ColumnB
FROM books
WHERE ColumnB LIKE '#firstletter#%'
ORDER BY ColumnB
</cfquery>

this is the error code: Too few parameters. Expected 1.

any help greatly appreciated.

oregonHoney

A: 

Update:

select *
from (
    SELECT title, a1_Lname as Name
    FROM books  
    WHERE a1_Lname LIKE '#firstletter#%' 
    UNION ALL
    SELECT title, a2_Lname as Name
    FROM books  
    WHERE a2_Lname LIKE '#firstletter#%' 
) a
ORDER BY Name
RedFilter
i must not have described the issue well enough...what i want to do is extend the column, that is, a1_Lname, so that it further lists all the names in the second column too, THEN alphabetizes this complete, longer list of names.the code above results in a list of NEW names which have been created by merging the last names of two people together. So now i have "Smithstevens" showing up instead of "smith" then "Stevens"
Honey Stowers
@Honey: see my update
RedFilter
A: 

In Jet/ACE SQL you can't place a WHERE clause or ORDER BY on a field-name alias -- you have to repeat the expression the alias is referring to. So, replace this:

  SELECT title, (a1_Fname + a2_Fname) AS ColumnA, (a1_Lname + a2_Lname) AS ColumnB
  FROM books
  WHERE ColumnB LIKE '#firstletter#%'
  ORDER BY ColumnB

...with this:

  SELECT title, (a1_Fname + a2_Fname) AS ColumnA, (a1_Lname + a2_Lname) AS ColumnB
  FROM books
  WHERE a1_Lname + a2_Lname LIKE '#firstletter#%'
  ORDER BY a1_Lname + a2_Lname

If you have Access installed, I strongly encourage you to test your SQL in interactive Access, in the QBE. You would quickly have discovered that this is the case if you'd just tried it within Access.

David-W-Fenton