I would like your help for a query. I have a temporary table with value(float), attribute(nvarchar) and system(int). I need to update the values depending the attribute, but using the system. So...
UPDATE #inventory (value, attribute)
SET (value, attribute) = (SELECT SUM(value), 'Actual'
FROM ReportValue v, ReportValueType t, ReportProducts ti
WHERE v.type_id = t.id
AND v.voyage_id = ti.id
AND t.value_code = 'total'
AND t.category_code = 'cold'
AND ti.end_time BETWEEN @start AND @end)
UPDATE #inventory (value, attribute)
SET (value, attribute) = (SELECT SUM(value), 'Actual'
FROM ReportValue v, ReportType t, Reportprod ti
WHERE v.type_id = t.id
AND v.voyage_id = ti.id
AND t.field_name = 'Total'
AND t.slot_type = 'COLD'
AND t.xml_id = -2000
AND ti.end_time BETWEEN @start AND @end)
else (value, attribute)
end
This is the wrong form. How can I get it working? Thank you in advance for your answers!
OK so it semms you are trying too get your head around update syntax... (that is compliant):
UPDATE tblNameCanBeTempTable
SET Column1 = S.Value1, Column2 = S.Value2, etc
FROM (anyValidSelectTableStatement) S
WHERE tblNameCanBeTempTable.KeyValue = S.keyValue
So the route is make your select statment, check it produces the values you want, then tack the update ont the beginning and the row matching WHERE on the end
You Can do things like
Col1 = CASE WHEN X=1 THEN S.Value1 ELSE Col1 END
for each row.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.