1

I have a fully working stored procedure grabbing data from different tables using joins. I am currently using the below SELECT statement to select the data I require:

SELECT ClientReference, ReferenceNumber, Text3, ReceiptDate, [dbo].[Complaint].[Description], ActionTaken, dbo.Category.Name, dbo.CategoryOption.FullName, dbo.Complaint.AuditCreatedBy, dbo.UserGroup.Name, dbo.Complaint.LoggedByUserId, dbo.Complaint.LoggedByTime FROM dbo.Complaint 

Now what I want to be able to do is insert this data into a temporary table. However, INSERT INTO does not work as I have two columns (resulting from my join) called Name.

How would I go about solving this?

4
  • Have you tried SELECT ... INTO #temp ..? Commented Apr 25, 2014 at 15:12
  • Did you try INSERT INTO with a field list, making sure you have separate field names for each NAME returned from your proc? Commented Apr 25, 2014 at 15:20
  • FYI, that's not a valid SELECT statement. I assume there's more to it? Commented Apr 25, 2014 at 15:25
  • Have you tried using aliases? Commented Apr 25, 2014 at 15:29

1 Answer 1

4

Just alias one of the Name columns:

SELECT ClientReference, ReferenceNumber, Text3, ReceiptDate, Complaint.Description, ActionTaken, Category.Name As CategoryName, CategoryOption.FullName, Complaint.AuditCreatedBy, UserGroup.Name, Complaint.LoggedByUserId, Complaint.LoggedByTime INTO #tempTable FROM dbo.Complaint ... 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.