0
希望我正確描述這一點。我有以下兩個SQL更新查詢單獨正常工作。我需要在第一個字段中更新字段,並在第二個字符的一部分中使用它。將兩個單獨查詢的內容合併爲一個,並更新
這是第一個。
UPDATE Products_Joined SET TechSpecs = 'var srating_'
+ Products_Joined.ProductCode + '="' + CAST(Reviews.AverageRating AS VARCHAR) + '";var rcount_' + Products_Joined.ProductCode + '="' + CAST(Reviews.TotalRatings AS VARCHAR) + '";'
FROM Products_Joined LEFT OUTER JOIN (
SELECT Reviews.ProductCode, AVG(Reviews.Rate) AS AverageRating, COUNT(Reviews.ReviewID) AS TotalRatings
FROM Reviews
GROUP BY Reviews.ProductCode
) AS Reviews ON Products_Joined.ProductCode = Reviews.ProductCode;
這是第二個。
DECLARE @OpenTag varchar(100)
SET @OpenTag = '<script type="text/javascript" language="javascript">'
UPDATE Products_Joined
SET TechSpecs = STUFF(CAST(TechSpecs AS VARCHAR(MAX)) ,
CHARINDEX(@OpenTag, CAST(TechSpecs AS VARCHAR(MAX)) ,1) + LEN(@OpenTag),
CHARINDEX('</script>',CAST(TechSpecs AS VARCHAR(MAX)) ,1)-(CHARINDEX(@OpenTag, CAST(TechSpecs AS VARCHAR(MAX)) ,1) + LEN(@OpenTag)),
'*****HERE IS WHERE I WANT TO PUT THE FIELD FROM THE FIRST SQL QUERY*******')
WHERE TechSpecs LIKE '%<script type="text/javascript" language="javascript">%</script>'
儘管這非常有幫助,但我很難理解如何將這一功能與我非常有限的SQL知識結合到上面。 – user357034 2012-01-14 13:28:30
您或其他人是否願意提供工作解決方案?謝謝 – user357034 2012-01-14 14:00:51