July 16, 2013 at 11:15 pm
Learn new thing. Thanks carlo π
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
July 16, 2013 at 11:58 pm
Hi,
as per the explanation- The stmt "return (select 5)" gives error because in a batch RETURN with integer_expression is not admitted (note: PARENTHESIS cast the SELECT to an integer_expression for RETURN).
Create PROCEDURE checkstate @param varchar(11)
AS
IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE BusinessEntityID = @param) = 'WA'
RETURN 1
ELSE
RETURN 2 ;
GO
declare @returnstatus int
EXEC @returnstatus = checkstate 291
select @returnstatus
But we use integer expression with RETURN in a stored procedure and it works...
I am confused that will integer expression works only in stored procedure and not in sql statements :blink:
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 17, 2013 at 12:59 am
Very interesting question, thanks!
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
July 17, 2013 at 1:29 am
kapil_kk (7/16/2013)
But we use integer expression with RETURN in a stored procedure and it works...
I am confused that will integer expression works only in stored procedure and not in sql statements :blink:
You are not the only one confused by the statement :unsure:
July 17, 2013 at 2:39 am
DevilsChest (7/17/2013)
kapil_kk (7/16/2013)
But we use integer expression with RETURN in a stored procedure and it works...
I am confused that will integer expression works only in stored procedure and not in sql statements :blink:
You are not the only one confused by the statement :unsure:
OK, if you dont have any confusion then plz then give the answer to my queries
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 17, 2013 at 2:49 am
kapil_kk (7/16/2013)
Hi,as per the explanation- The stmt "return (select 5)" gives error because in a batch RETURN with integer_expression is not admitted (note: PARENTHESIS cast the SELECT to an integer_expression for RETURN).
Create PROCEDURE checkstate @param varchar(11)
AS
IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE BusinessEntityID = @param) = 'WA'
RETURN 1
ELSE
RETURN 2 ;
GO
declare @returnstatus int
EXEC @returnstatus = checkstate 291
select @returnstatus
But we use integer expression with RETURN in a stored procedure and it works...
I am confused that will integer expression works only in stored procedure and not in sql statements :blink:
It's easy: in a BATCH, you can use RETURN, but without a return value. In functions and procs you can use RETURN with an integer value!
Do you know the difference between BATCH, FUNCTS and PROCS? π
July 17, 2013 at 2:58 am
Carlo Romagnano (7/17/2013)
kapil_kk (7/16/2013)
Hi,as per the explanation- The stmt "return (select 5)" gives error because in a batch RETURN with integer_expression is not admitted (note: PARENTHESIS cast the SELECT to an integer_expression for RETURN).
Create PROCEDURE checkstate @param varchar(11)
AS
IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE BusinessEntityID = @param) = 'WA'
RETURN 1
ELSE
RETURN 2 ;
GO
declare @returnstatus int
EXEC @returnstatus = checkstate 291
select @returnstatus
But we use integer expression with RETURN in a stored procedure and it works...
I am confused that will integer expression works only in stored procedure and not in sql statements :blink:
It's easy: in a BATCH, you can use RETURN, but without a return value. In functions and procs you can use RETURN with an integer value!
Do you know the difference between BATCH, FUNCTS and PROCS? π
Yes I know the differences between these....
Thanks its clear to me now π
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 17, 2013 at 4:19 am
kapil_kk (7/17/2013)
Carlo Romagnano (7/17/2013)
kapil_kk (7/16/2013)
Hi,as per the explanation- The stmt "return (select 5)" gives error because in a batch RETURN with integer_expression is not admitted (note: PARENTHESIS cast the SELECT to an integer_expression for RETURN).
Create PROCEDURE checkstate @param varchar(11)
AS
IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE BusinessEntityID = @param) = 'WA'
RETURN 1
ELSE
RETURN 2 ;
GO
declare @returnstatus int
EXEC @returnstatus = checkstate 291
select @returnstatus
But we use integer expression with RETURN in a stored procedure and it works...
I am confused that will integer expression works only in stored procedure and not in sql statements :blink:
It's easy: in a BATCH, you can use RETURN, but without a return value. In functions and procs you can use RETURN with an integer value!
Do you know the difference between BATCH, FUNCTS and PROCS? π
Yes I know the differences between these....
Thanks its clear to me now π
I imagine the wording of the answer options (for example "Batch 1 returns 1") was chosen to allow that confusion. The reason that you can't use return with a value in a batch is that batches don't return scalar values, they return (possibly empty) result sets or they don't return anything or they raise an error. So technically every one of the answers options is misusing "return" in a way that makes it incorrect, and while it's fairly common usage to use return in that manner it is confusing to do so when discussion the RETURN primitive in SQL.
But it's a nice fun question anyway.
Tom
July 17, 2013 at 4:20 am
Nice one.....
July 17, 2013 at 5:07 am
This was removed by the editor as SPAM
July 17, 2013 at 8:26 am
Nice qn.
July 17, 2013 at 8:34 am
Excellent Question
Malleswarareddy
I.T.Analyst
MCITP(70-451)
July 17, 2013 at 9:18 am
L' Eomot InversΓ© (7/17/2013)
The reason that you can't use return with a value in a batch is that batches don't return scalar values, they return (possibly empty) result sets or they don't return anything or they raise an error.
Thanks for the explanation, Tom. I had no idea batches could return anything at all.
Also, thank you Carlo for the question. I loved the trick with non-existing table! π
July 17, 2013 at 10:19 am
Thanks Tom for the explanation.......
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 15 posts - 1 through 15 (of 25 total)
You must be logged in to reply to this topic. Login to reply