Link to home
Start Free TrialLog in
Avatar of Abiel de Groot
Abiel de GrootFlag for Spain

asked on

TSQL put recordset into new table for mail merge

Hi All,

I need some help with TSQL. I want to run the following on a remote SQL. It currently works and correctly returns the data. However, I want it to write the recordset to a new table 'Temp_MailMerge_Table' . AS the name implies, its so as I can use it for a mail merge in WORD 2007.

---
SELECT us.User_ID
  , us.User_UN
  , us.User_PW
  , us.User_Email
  , pa.Parnets_ParentNames

FROM Tbl_Users us

Left JOIN Tbl_Parents pa ON
us.User_ID = pa.Parents_UserID

WHERE us.User_Type = 3


'NOT sure how this bit is written in TSQ

1 - Empty Temp_MailMerge_Table
2 - PUT this data into Temp_MailMerge_Table
SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Abiel de Groot

ASKER

Hi Appari,

Many thanks, but I get an error.

------------------
Mens. 213, Nivel 16, Estado 1, Línea 3
El nombre de columna o los valores especificados no corresponden a la definición de la tabla.
---------
Column names or specified values do not correspond.


The columns with the TEMP table are in the order of the select statment and the data types are corresponding. However they have different names. I have amended the statement as follows but still get the same error.

Amy advice?

The 'AS' changes it to the actual column name in the TEMP table.

---------------------

delete from Temp_MailMerge_Table;

insert into Temp_MailMerge_Table
SELECT us.User_ID AS Temp_User_ID
  , us.User_UN AS Temp_User_UN
  , us.User_PW AS Temp_User_PW
  , us.User_Email AS Temp_User_Email
  , pa.Parnets_ParentNames AS Temp_Parnets_ParentNames

FROM Tbl_Users us

Left JOIN Tbl_Parents pa ON
us.User_ID = pa.Parents_UserID

WHERE us.User_Type = 3
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A masterclass ... many thanks guys

A.