2017-10-18 23 views
0

J'ai une requête. cette requête est calculée en pourcentage pour chaque produit. J'ai créé une colonne virtuelle sur cette requête, le nom de cette colonne est 'yüzde'. Après cela, je veux transférer des colonnes yüzde à une autre colonne dans une autre table avec une requête de mise à jour si les identifiants de produit sont identiques. Je pense que je dois écrire une procédure stockée. Comment puis je faire ça?comment transférer des valeurs vers une autre colonne avec deux requêtes

SELECT [ProductVariantId] , 
     count([ProductVariantId]) as bedensayısı, 
     count([ProductVariantId]) * 100.0/(SELECT Top 1 Count(*) as Total  
    FROM [Live_ADL].[dbo].[_INV_ProductCombinationAttributes] 
    Where Size LIKE '%[^0-9]%' and [StockQuantity]>0 
    Group by [ProductVariantId] 
    order by Total Desc) as yüzde 
FROM [Live_ADL].[dbo].[_INV_ProductCombinationAttributes] 
Where Size LIKE '%[^0-9]%' and [StockQuantity]>0 
group by [ProductVariantId] 
order by yüzde desc 

enter image description here

Répondre

0

vous n'avez pas vraiment besoin d'un SP, vous pouvez le faire en ligne, en utilisant CTE par exemple, quelque chose le long de ces lignes:

; with tabyuzde as 
(
SELECT [ProductVariantId] , 
     count([ProductVariantId]) as bedensayısı, 
     count([ProductVariantId]) * 100.0/(SELECT Top 1 Count(*) as Total  
    FROM [Live_ADL].[dbo].[_INV_ProductCombinationAttributes] 
    Where Size LIKE '%[^0-9]%' and [StockQuantity]>0 
    Group by [ProductVariantId] 
    order by Total Desc) as yüzde 
FROM [Live_ADL].[dbo].[_INV_ProductCombinationAttributes] 
Where Size LIKE '%[^0-9]%' and [StockQuantity]>0 
group by [ProductVariantId] 
) 

update x 
set othertablevalue=yüzde 
from 
othertable x 
join tabyuzde t on x.ProductVariantId=t.ProductVariantId 
+0

Merci. Cela marche –