Click here to Skip to main content
12,897,457 members (51,343 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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
Posted 14-Feb-13 22:34pm
Updated 14-Feb-13 23:11pm
v4
Comments
Nandakishorerao 15-Feb-13 4:55am
   
what have you done till now?paste it

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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()
  Permalink  
v3
Comments
Rohit Kolekar11 15-Feb-13 5:01am
   
Ok thank you.... Can u please send me how to do it by using functions?
Chris Reynolds (UK) 15-Feb-13 5:41am
   
Updated solution for functions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100