因此,我試圖根據電子郵件地址是否存在於數據庫中而將子查詢的結果轉換爲參數。一旦找到它,我希望它將找到的行的ID設置爲@ID並刪除該行。但是,我收到以下錯誤:SQL錯誤:「子查詢未與EXISTS一起引入時,只能在選擇列表中指定一個表達式。」不知道如何修復
「子查詢未使用EXISTS引入時,只能在選擇列表中指定一個表達式。」
我已經搜索了高和低的答案,但我來空。我究竟做錯了什麼?我該如何解決它?
隨時留下任何建議,我可以做得更好。謝謝!
DECLARE @EmailAddr varchar(255)
DECLARE @ID int
DECLARE @Email_Text varchar(max)
SET @EmailAddr = (SELECT TOP 1 Email FROM tempdb.dbo.WarrantyAnniversaryEmail)
WHILE (SELECT COUNT(Email) FROM tempdb.dbo.WarrantyAnniversaryEmail WHERE Email = @EmailAddr) > 0
BEGIN
SET @Email_Text = @Email_Text + ';' + (SELECT TOP 1 Id, [First] + ' ' + [Last] as FullName, @EmailAddr, Company, Phone, [Address] + ', ' + City + ', ' + [State] + ' ' + Zip as FullAddress
FROM tempdb.dbo.WarrantyAnniversaryEmail
WHERE Email = @EmailAddr)
SET @ID = (SELECT TOP 1 Id FROM tempdb.dbo.WarrantyAnniversaryEmail WHERE Email = @EmailAddr)
DELETE FROM tempdb.dbo.WarrantyAnniversaryEmail WHERE Id = @ID
PRINT @Email_Text
END
錯誤信息的哪個方面沒有得到? –