在sql server中使用程序 [英] Using procedures in sql server

查看:52
本文介绍了在sql server中使用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果项目中的count(问题)为0

返回1

否则if(count(issue)> 0和count(issue)< 5)

返回0

其他

返回-1



我要创建功能对于上面的sql ...

请给我打电话怎么办

if count(issue) in project is 0
return 1
else if(count(issue)>0 and count(issue)<5)
return 0
else
return -1

I want to create function for above in sql...
Please tel me how to do

推荐答案

你的问题缺乏细节。你能确认一下你有哪些SQL表吗?看起来你试图计算表中的行数并根据它返回一个值。它只是表中的总行数还是基于某些条件。以下内容可能会对您有所帮助



Your question is lacking in detail. Can you confirm what SQL tables you have. It looks like you''re trying to count the number of rows in a table and return a value depending on that. Is it just total rows in the table or based on some condition. The following might help you

CREATE PROCEDURE SampleProc 

AS
BEGIN
	DECLARE @RowCount int
	SELECT @RowCount = COUNT(*) FROM project
	IF @RowCount = 0 
	BEGIN
		RETURN 1
	END
	IF @RowCount > 0 AND @RowCount < 5
	BEGIN
		RETURN 0
	END
	RETURN -1
END
GO

-- Sample call
DECLARE @RC int
 EXEC @RC = SampleProc
PRINT @RC





或作为功能:





or as a function:

CREATE FUNCTION dbo.SampleFunc() RETURNS int
AS
BEGIN
    DECLARE @RowCount int
    SELECT @RowCount = COUNT(*) FROM project
    IF @RowCount = 0
    BEGIN
        RETURN 1
    END
    IF @RowCount > 0 AND @RowCount < 5
    BEGIN
        RETURN 0
    END
    RETURN -1

END
GO

select dbo.SampleFunc()


这篇关于在sql server中使用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆