有人能幫助請我不知道我做錯了:SQL腳本句法和語法問題
IF EXISTS (SELECT name
FROM sys.tables
WHERE name = N'MemberIdsToDelete')
DROP TABLE [MemberIdsToDelete];
GO
SELECT mm.memberid ,
mm.aspnetuserid ,
mm.email ,
mm.RowNum AS RowNum
INTO #MemberIdsToDelete
FROM membership.members AS mm
LEFT JOIN aspnet_membership AS asp ON mm.aspnetuserid = asp.userid
LEFT JOIN trade.tradesmen AS tr ON tr.memberid = mm.memberid
WHERE asp.isapproved = 0
AND tr.ImportDPN IS NOT NULL
AND tr.importDPN <> ''
ORDER BY mm.memberid
DECLARE @MaxRownum INT
SET @MaxRownum = (SELECT MAX(RowNum)
FROM #MemberIdsToDelete
)
DECLARE @Iter INT
SET @Iter = (SELECT MIN(RowNum)
FROM #MemberIdsToDelete
)
DECLARE @MemberId INT
DECLARE @TrademId INT
DECLARE @UId UNIQUEIDENTIFIER
DECLARE @Successful INT
DECLARE @OutputMessage VARCHAR(200)
DECLARE @Email VARCHAR(100)
DECLARE @Username VARCHAR(100)
SELECT @MemberId = memberId ,
@UId = AspNetUserId
FROM MemberIdsToDelete
SELECT @TrademId = TradesManId
FROM trade.TradesMen
WHERE memberId = @MemberId;
WHILE @Iter <= @MaxRownum
BEGIN
SELECT *
FROM #MemberIdsToDelete
WHERE RowNum = @Iter
--more code here
SET @Iter = @Iter + 1
END
我只是想檢查我的表MemberIdsToDelete存在,如果是這樣砸, 與創建MemberIdsToDelete結果從通過MemberIdsToDelete表的SELECT 迴路設置和執行操作
我收到錯誤ROWNUM不存在
我仍然收到錯誤:無效的列名'RowNum'。和無效的對象名稱'#MemberIdsToDelete'關於如果存在,yikes我知道MySql向後但sql是另一回事:) –
請參閱編輯我的答案... – MoonKnight
謝謝,所以爲了創建臨時表,我可以只是運行選擇?我試過,仍然有錯誤無效的列名「RowNum' –