sql语句执行的疑惑
sql语句:select sum(ProductPrice) from sale where ProductDate like''+@ProductDate+'%' and Name=@Name
当给出正确的模糊条件时能够查出数据 并返回sum求出的和 但条件不符合时 为什么仍执行查询 但sum没有返回值!
急!急!
小弟第一次发帖求助,望高手指点!谢谢!
like''+@ProductDate+'%'
是一行一行来对比的!如果有就放在sum()
查询最还没有体配的话就没有返回值罗!
最好加上统计函数!来判断是否体配行!
谢谢您的回复!
应当这么写,当条件不符合就返回0
sql语句:select IsNull(sum(ProductPrice),0) from sale where ProductDate like''+@ProductDate+'%' and Name=@Name
!
like '% + @Name + %'";
string s="select * from Tb where Name like N'%'+@Name +'%'";
SQL code:
SELECT ISNULL
(select sum(ProductPrice)
from sale
where ProductDate like @ProductDate+'%'
and Name=@Name),0)
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
刚刚接触MySQL,不知道该如何去查看数据,插入数据,创建数据库、表,用哪为前辈能指教一二?
MySQL 5.1参考手册
引用
兄弟你会结贴吗?
mysql 参考手册
baidu
MySQL官方文档 http://dev.mysql.com/doc ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......