How can I transform this table from this
id name
1 sam
2 nick
3 ali
4 farah
5 josef
6 fadi
to
id1 name1 id2 name2 id3 name3 id4 name4
1 sam 2 nick 3 ali 4 farah
5 josef 6 fadi
the reason i need this is i have a database and i need to do a mail merge using word and I want to print every 4 rows on one page, MS word can only print one row per page, so using an SQL query I want one row to represent 4 rows
thanks in advance
Ali
You don’t need to create a query for this in Access. Word has a merge field called
<<Next Record>>which forces moving to the next record. If you look at how label documents are created using the Mail Merge Wizard, you’ll see that’s how it’s done.Updated – Doing this in SQL
The columns in simple
SELECTstatements are derived from the columns from the underlying table/query (or from expressions). If you want to define columns based on the data, you need to use a crosstab query.First create a query with a running count for each person (say your table is called
People), and calculate the row and column position from the running count:(You won’t be able to view this in the Query Designer, because the
JOINisn’t comparing with=but with>=.)This query returns the following results:
Assuming this query is saved as
Positions, the following query will return the results:The
UNIONis there so each record in thePeopletable will have two columns – one with theid, and one with thename.The
PIVOTclause forces the columns to the specified order, and not in alphabetical order (e.g.id1,id2…name1,name2…)