Click here to Skip to main content
15,921,062 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

Please any one can help me.
I want to insert a break keyword in my Function.
Can anyone let me know how I can achieve this.

Thanks

SQL
ALTER FUNCTION [dbo].[islistthere]
(
	@ent	char(4), 	@Id int, @month char(4), @sec int
)
RETURNS char(5)  AS
BEGIN
	DECLARE @Table1 int
	DECLARE @Table2 int
	DECLARE @Add char(5)
	SET @Add = 'false'

	SET @Table1 = ( SELECT COUNT(PRID) FROM PR WHERE PRID = @Id and ent = ltrim(rtrim(@ent)) and TMonth=@month)
	SET @Table2 = ( SELECT COUNT(PRDID) FROM PRD WHERE PRID = @Id andent = ltrim(rtrim(@ent)) and TMonth=@month and TSec=@sec)

	IF (@sec = 0 AND @Table1 = 0 )
		SET @Add = 'true'	

 
	IF (@sec > 0 AND @Table1 = 1 AND @Table2 = 0 )
		SET @Add = 'true'
	

	
	
		
	RETURN @Add 
END
Posted
Updated 1-Aug-13 23:33pm
v2
Comments
Maciej Los 2-Aug-13 5:36am    
What kind of break?
babli3 2-Aug-13 5:40am    
I want this statement to execute one by one... so I want to add a break keyword to this function.Thanks
Samresh.ss 2-Aug-13 5:38am    
What do you wish to achieve?
babli3 2-Aug-13 5:40am    
I want this statement to execute one by one... so I want to add a break keyword to this function.Thanks
Samresh.ss 2-Aug-13 5:45am    
The statements will execute one by one.

OriginalGriff has mentioned a nice link.

but I think you want to check you SP in parts in SSMS.(Not in your code) like "exec spname"

so you can use return for this purpose.


ALTER FUNCTION [dbo].[islistthere]
(
	@ent	char(4), 	@Id int, @month char(4), @sec int
)
RETURNS char(5)  AS
BEGIN
	DECLARE @Table1 int
	DECLARE @Table2 int
	DECLARE @Add char(5)
	SET @Add = 'false'
 
	SET @Table1 = ( SELECT COUNT(PRID) FROM PR WHERE PRID = @Id and ent = ltrim(rtrim(@ent)) and TMonth=@month)

select @Table1
return -- it will return from here and would not execute other statements

	SET @Table2 = ( SELECT COUNT(PRDID) FROM PRD WHERE PRID = @Id andent = ltrim(rtrim(@ent)) and TMonth=@month and TSec=@sec)
 
	IF (@sec = 0 AND @Table1 = 0 )
		SET @Add = 'true'	
 
 
	IF (@sec > 0 AND @Table1 = 1 AND @Table2 = 0 )
		SET @Add = 'true'
	
 
	
	
		
	RETURN @Add 
END


but once you done with checking don't forget to remove these extra "return" from your sp, Otherwise it will give error/wrong output.
 
Share this answer
 
v2
Comments
babli3 2-Aug-13 7:10am    
Thank you ...I will try this
Adarsh chauhan 2-Aug-13 7:12am    
you are most welcome..
babli3 2-Aug-13 7:37am    
Hi Adarsh
Its throwing me an error...
Adarsh chauhan 2-Aug-13 7:39am    
what error is it giving??
babli3 2-Aug-13 9:01am    
Thank You ....
Its working now ...Actually it didnt require any break...as it was executing line by line.Thank You for your help:)
Probably, what you are looking for is how to debug an SQL function.
See here: Walkthrough: Debugging a T-SQL User-Defined Function[^]
 
Share this answer
 
Comments
babli3 2-Aug-13 7:38am    
Thank You
OriginalGriff 2-Aug-13 7:57am    
You're welcome!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900