Click here to Skip to main content
15,888,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day

how can I how can i get the results from the CTE below to be actually added to a table(apicultureentries). your help will be greatly appreciated. I am using Sql Server 2016


With AllMarks AS
(SELECT
CompetitorID,
ApiEntryId,
AverageMark,
RANK() OVER (ORDER BY AverageMark)AS RankPosition


FROM ApicultureEntries
)
SELECT
a.*,(CASE WHEN a.RankPosition < 14 THEN 150 - RankPosition * 10 ELSE NULL END) AS PositionEarned
FROM AllMarks AS a

What I have tried:

insert into apiculture , select into
Posted
Updated 7-Mar-18 5:39am

1 solution

It's quite obvious...

SQL
With AllMarks AS
(
...
)
INSERT INTO TableName (<List_Of_Columns>)
SELECT a.<List_Of_Columns>, (CASE WHEN a.RankPosition < 14 THEN 150 - RankPosition * 10 ELSE NULL END) AS PositionEarned
FROM AllMarks AS a


For further details, please see: INSERT (Transact-SQL) | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 13392936 7-Mar-18 16:00pm    
thanks much. gonna try and provide feedback

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900