0

mysql toadを使用しています。空のテーブルがあり、レコードが見つからない場合は文字列値を返そうとしていますが、言及されているクエリを試しましたが、何も機能せず、空の行のみが返されます。

クエリ

select coalesce(stDate,'0')as StDate from tblStudents where studentNumber = 12213123;

select IFNULL(stDate,'0')as StDate from tblStudents where studentNumber = 12213123;

結果は空の文字列のみで、列 stDate は varchar 型です。

4

1 に答える 1

1

これを試して

 select Cast(count(*) as char(10)) as StDate
 from tblStudents where studentNumber = 12213123;

CASE ステートメントを使用することもできます。学生番号が一意の場合は、max() または min() 関数を使用してテーブルから stDate を取得します。

 select Cast(count(*) as char(10)) as NumRows,max(stDate) as stDate
 from tblStudents where studentNumber = 12213123;

単一のフィールドのみが必要な場合は、次のようにしてください

select 
CASE count(*)
    WHEN 0 THEN ''
    ELSE CAST(max(stDate) as char(12))
END CASE as StartDate
     from tblStudents where studentNumber = 12213123;
于 2013-05-04T02:12:19.537 に答える