2017-03-27 1 views
0

このスクリプトで動作するcaseステートメントを入手するには、初めてそれを試して、何が間違っているのか分からない。エイリアスを含むケースステートメント

SELECT DocumentDest.Keycode AS [Acct #], 
     Customer.Name, 
     DocumentDest.Emails, 
     Case 
      Customer.Freq AS [Weekly or Monthly] 
      When 'W' then 'Weekly' 
      When 'M' then 'Monthly' 
      Else 'None' 
     End 
FROM  DocumentDest 
INNER JOIN Customer ON DocumentDest.Keycode = Customer.KeyCode 
WHERE (DocumentDest.Type = 'cus') AND (DocumentDest.[Document] IN ('stmt', 'wstmt')) 
+1

MySQLではありません。 SQL-SERVER –

+0

はい、正しいですか? – Steve

+0

@スティーブ:不一致の二重引用符を一重引用符に変更しました。私はこれがあなたの問題に関連していないと仮定していますか? –

答えて

0

エイリアスWeekly or MonthlyCASE文の真ん中に表示されていない必要があります。これは、それに応じてMySQLのフォームエイリアスのために、SQL-Serverのバージョンです。

SELECT 
     DocumentDest.Keycode AS [Acct #], 
     Customer.Name, 
     DocumentDest.Emails, 
     Case Customer.Freq When 'W' then 'Weekly' When 'M' then 'Monthly' Else 'None'  
     End AS [Weekly or Monthly] 
    FROM DocumentDest INNER JOIN Customer 
    ON DocumentDest.Keycode = Customer.KeyCode 
    WHERE DocumentDest.Type = 'cus' 
    AND DocumentDest[Document IN ('stmt', 'wstmt') 
+0

したがって、Caseステートメントは別名も作成します。とった。ありがとうございました。 – Steve

+0

あなたの仕事は大歓迎です。 –

関連する問題