[英]MySql Toad if now rows return value
I am using mysql toad , i have a table which is empty and i am trying to return a string value if no records are found i have tried the under mention queries however none works, only an empty row is returned. 我正在使用mysql toad ,我有一个空的表,如果没有找到记录,我试图返回一个字符串值。我尝试了下面提到的查询,但是没有用,只返回一个空行。
Query 询问
select coalesce(stDate,'0')as StDate from tblStudents where studentNumber = 12213123;
select IFNULL(stDate,'0')as StDate from tblStudents where studentNumber = 12213123;
The results are only empty strings the column stDate is of type varchar. 结果仅为空字符串,列stDate为varchar类型。
Try this 尝试这个
select Cast(count(*) as char(10)) as StDate
from tblStudents where studentNumber = 12213123;
You can also use the CASE statement, and if the Student Number is unique, the max() or min() functions to get the stDate from the table. 您还可以使用CASE语句,如果“学生编号”是唯一的,则max()或min()函数可从表中获取stDate。
select Cast(count(*) as char(10)) as NumRows,max(stDate) as stDate
from tblStudents where studentNumber = 12213123;
If you only want a single field, try something like this 如果您只想要一个字段,请尝试这样的操作
select
CASE count(*)
WHEN 0 THEN ''
ELSE CAST(max(stDate) as char(12))
END CASE as StartDate
from tblStudents where studentNumber = 12213123;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.