Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

take results of select and map it to an insert statement

This is the selection I want:

select into insert
I want insert into table AgentFormList using the SELECT shown above.  Not sure about the syntax.
0
Tom Knowlton
Asked:
Tom Knowlton
  • 3
1 Solution
 
Steve WalesSenior Database AdministratorCommented:
insert into AgentFormList
select <rest of your select statement here>
0
 
Tom KnowltonWeb developerAuthor Commented:
Yep!


use PP

INSERT INTO [PP].[dbo].[AgentFormList]
           ([AgentFormListSID]
           ,[FormTypeID]
           ,[Sequence]
           ,[FormName]
           ,[ColistFlag]
           ,[AcceptanceReqd]
           ,[DuplicatesAllowed]
           ,[ExternalLink]
           ,[TaskCode]
           ,[AMFID]
           ,[AMFSID]
           ,[ClientID]
           ,[ClientSID]
           ,[ProductID]
           ,[Active])
select
 
      1
      ,[afl].[FormTypeID]
      ,[afl].[Sequence]
      ,[afl].[FormName]
      ,[afl].[ColistFlag]
      ,[afl].[AcceptanceReqd]
      ,[afl].[DuplicatesAllowed]
      ,[afl].[ExternalLink]
      ,[afl].[TaskCode]
      ,[AmFClient].[AMFirmID]
      ,[AmFClient].[AMFirmSID]
      ,[AmFClient].[MerchantID]
      ,[AmFClient].[MerchantSID]
      ,1
      ,1
from agentformlist afl --18*24
cross join (select
              distinct
              Asset.AMFirmID,
              Asset.AMFirmSID,
              Pool.MerchantID,
              Pool.MerchantSID
            from Asset  
            join Pool  on
            Pool.PoolID = Asset.PoolID
            AND Pool.PoolSID = Asset.PoolSID
            ) AS AmFClient
0
 
Tom KnowltonWeb developerAuthor Commented:
Thanks!
0
 
TempDBACommented:
You can use insert into select combination as expert sjwales suggested above (No points plz)

INSERT INTO TABLENAME (COL1, COL2, COL3, ......, COLN)
SELECT af1.col1,
            af2.col2,
            .
            .
            afn.coln,
            AmFClient.col1,
            AmFClient.col2,
            .
            .
            AmFClient.colm
FROM bla bla bla...

NOTE:- n+m = N
0
 
Tom KnowltonWeb developerAuthor Commented:
TempDBA:

Thanks!
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now