Home > Database > Mysql Tutorial > sqlserver2008中自定义函数的问题

sqlserver2008中自定义函数的问题

WBOY
Release: 2016-06-07 15:33:58
Original
1154 people have browsed it

数据库中有一个字段,数据类型为date,现在我想定义一个函数,输入参数为date类型,返回的数据为与输入参数相同年份和月份的数据行数,在函数体中使用了count函数。 create function [dbo].[Time](@times date) returns int as begin return( select COUNT(*

数据库中有一个字段,数据类型为date,现在我想定义一个函数,输入参数为date类型,返回的数据为与输入参数相同年份和月份的数据行数,在函数体中使用了count函数。

create function [dbo].[Time](@times date)
returns int
as
begin 
 return(

select COUNT(*)
 from Question
 where datediff(yy,PublishedTime,@times)=0

and DATEDIFF(mm,PublishedTime,@times)=0)
end
 使用语句为:

select dbo.Time('2012-12-20')

from Question

但是为题是查出来的结果数量为表Question中数据的行数。为什么会查询出那么多行的数据,而不是单一的一行数据?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template