我試圖更新存儲在SQL Server的博客中的評論和/或評級2012年正確的SQL語法和值
我需要檢查,如果該評論是一個空字符串,如果通過該代碼塊。
我需要檢查評級是否爲0.0,如果是的話繞過該代碼塊。註釋和評級使用標記[Comment]
,[RatingValue]
注入到SQL語句中。
上面的正確語法是什麼?以下是我已經試過:
IF [Comment] <> ""
UPDATE EasyDNNNewsComments
SET Comment = '[Comment]'
WHERE CommentID = [CommentID]
ELSE IF [NewRating] <> 0.0
SELECT
EasyDNNNewsComments.Comment, EasyDNNNewsComments.DateAdded,
EasyDNNNewsComments.UserID, EasyDNNNewsComments.CommentID,
Users.UserName
FROM
EasyDNNNewsComments
INNER JOIN
Users ON EasyDNNNewsComments.UserID = Users.UserID
WHERE
(ArticleID = [ArticleID])
ORDER BY
EasyDNNNewsComments.CommentID DESC
UPDATE ArticleRating
SET RatingValue = [NewRating]
WHERE ArticleID = [ArticleID] AND UserID = [UserID]
UPDATE EasyDNNNews
SET RatingValue = (SELECT Sum(RatingValue) FROM ArticleRating WHERE ArticleID = [ArticleID])/(SELECT Count(*) FROM ArticleRating WHERE ArticleID = [ArticleID])
SELECT RatingValue
FROM EasyDNNNews
WHERE ArticleID = [ArticleID]
IF [評論] <>「」應該是單引號,除非你'設置QUOTED_IDENTIFIER OFF' – scsimon
我不知道你想做的事,但是這個代碼並沒有太大的SENCE。什麼是「[評論]」?這應該是一個變量? (同樣適用於''CommentID]','[NewRating]'ect'。 –