本人初学不太懂求解
查询并返回product产品表中产品名称以C开头的产品的条数
要求:产品名称以C开头的条件用变量来表示,查询出来的产品条数也用变量表示,并最终需要返回'The sum of the product is' +查询出来的产品条数。
sql
[解决办法]
--个人觉得你的这句回 “The sum of the product is ” 多此一举
--当然,你非要这句,那就这么输出了
declare @num int
declare @result varchar(100)
select @num=count(1) from product where 产品名称 like 'C%'
set @result='The sum of the product is '+cast(@num as varchar(100))
select @result as N'结果'
declare @prod_name varchar(20);
declare @result varchar(100);
set @prod_name = 'c'
set @result = 'The sum of the product is '
select @result = @result + CAST(COUNT(*) as varchar)
from product
where prod_name like @prod_name +'%'