I have such an SQL:
SELECT p.PID,
p.HitIndex,
p.Smiles,
p.EntityID,
pp.mw AS MW,
pp.heavyatoms AS HeavyAtoms,
pp.tpsa AS TPSA,
pp.lipinskihba AS Lipinskihba,
pp.lipinskihbd AS Lipinskihbd,
pp.rotb AS RotB,
pp.xlogp AS XlogP,
pp.ro5 AS RO5,
pp.bbbarcode AS BBBarcode
FROM (SELECT pr.PID,
p.HitIndex,
p.Smiles,
p.EntityID,
(CASE WHEN PropVal IS NULL THEN PropStrVal ELSE PropVal END) AS PropVal,
PropName
FROM V_DELProdProps pr
JOIN DELProducts p ON p.PID = pr.PID) Temp
PIVOT (MAX(PropVal)
FOR [PropName] IN ([mw], [heavyatoms], [tpsa], [lipinskihba], [lipinskihbd], [rotb], [xlogp], [ro5], [bbbarcode])) pp
JOIN DELProducts p ON pp.PID = p.PID;
GO
What I want is to feed inside the MAX aggregation function float
and nvarchar
for different columns, but I am not sure how to do that correctly, how I can restructure the query.
Here is some data for V_DELProdProps
:
And for DELProducts
:
Here is an example output. The only thing that needed to be fixed here is getting correct values for the BBBarcode
:
As you can see PID
s are not duplicate in the result and that's how it should be.