0

I am trying to insert into table variable using following query. but its throwing an error. Please help on inserting multiple selects using single insert statement.

      DECLARE @AddressRecordsToPurge TABLE  
    (  
      RowID INT NOT NULL PRIMARY KEY IDENTITY(1,1),  
        GUIDValue Nvarchar(max) ,  
     GuidColumn Nvarchar(max) ,  
      GuidTable Nvarchar(max)  
     )    

    Insert Into @AddressRecordsToPurge values ( (Select            
    EMPLOYMENTSEQUENCENUMBER FROM ACCOUNTANTSREFERENCE  WHERE  
    CustomerNumber =  @CustomerNumber AND Customerversionnumber =  
    @CustomerVersionNumber AND EMPLOYMENTSEQUENCENUMBER IS NOT 
     NULL), 'EMPLOYMENTSEQUENC ENUMBER', 'ACCOUNTANTSREFERENCE'); 

My select statement returns multiple values and I want to have it this way only. Please help!

1 Answer 1

4

Your syntax is slightly off:

Insert Into @AddressRecordsToPurge (GuidValue, GuidColumn, GuidTable)
SELECT EMPLOYMENTSEQUENCENUMBER, 'EMPLOYMENTSEQUENCENUMBER', 'ACCOUNTANTSREFERENCE'
FROM ACCOUNTANTSREFERENCE
WHERE CustomerNumber =  @CustomerNumber
    AND Customerversionnumber = @CustomerVersionNumber
    AND EMPLOYMENTSEQUENCENUMBER IS NOT NULL; 
Sign up to request clarification or add additional context in comments.

1 Comment

You are legend brother. It worked as smooth as cheesecake..cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.