Share via


How to Exit from SQL Server Function ?

Question

Friday, July 2, 2010 3:35 PM

Hi friends,

I have a SQL Server Function, which concatanating Last Names.

I would like to do Exit from the Function, When Len(LastName) > 4000.

how can we do Exit fromthe SQL Server Function, when condition satisfied ?

Thanks.

All replies (7)

Friday, July 2, 2010 5:48 PM ✅Answered

The other alternative is SET based operation. If you post the function code, we'll tell you alternatives.Premature optimization is the root of all evil in programming. (c) by Donald Knuth

Naomi Nosonovsky, Sr. Programmer-Analyst

My blog


Friday, July 2, 2010 3:43 PM

Use RETURN command

IF Len(@LastName) > 4000

   return @LastName

Premature optimization is the root of all evil in programming. (c) by Donald Knuth

Naomi Nosonovsky, Sr. Programmer-Analyst

My blog


Friday, July 2, 2010 5:05 PM

Thanks for giving reply.

below is my detail description.

I have a Function which has CURSOR.

CURSOR concatanating Last Name to display in one row.

But When Len(@Lastname) - which is a CURSOR Variable , i would like to Exit from the Function.

how can i Exit if lenght is >4000 , after Contanating LastName ?

 

 


Friday, July 2, 2010 5:34 PM

1. Are you sure CURSOR is necessary? 

You can set the @ReturnCode = 1 then this condition is met and have the cursor select ... where ... and @ReturnCode  = 0

Premature optimization is the root of all evil in programming. (c) by Donald Knuth

Naomi Nosonovsky, Sr. Programmer-Analyst

My blog


Friday, July 2, 2010 5:46 PM

I am using a Cursor , and it is slwodown store procedure.

Instead of Cursor , what is other alternative ?

 


Friday, July 2, 2010 5:55 PM

Here, in this public column i can not post my code.

IF you do not mind, if you provide me your e-mail id, i can e-mail you code.

thanks.


Wednesday, July 7, 2010 5:40 AM

Here, in this public column i can not post my code.

Just make up a version of your code with the same issue and post it. Use AdventureWorks2008 data if possible.Kalman Toth, SQL Server & Business Intelligence Training; SQL 2008 GRAND SLAM