473,503 Members | 7,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The function Len; maybe a solution

1 New Member
Hi guys,

I'm not expert in SQL and my english is not perfect too, but I tried to find a solution about the Len problem. You know, if we try to get the Len of (' 123 '), we get 4 because all [space] on right side are trimmed. I did a little function to correct this bug and I would like to have your feedback and suggestion.

Thank you.

CREATE FUNCTION MyLen
(
@Text nvarchar(4000)
)
RETURNS int
AS
BEGIN
DECLARE @LoopDone bit,
@LenText int,
@Char nvarchar(1)

--************************************************** *************
-- This part count each char found in the text. That replace the function Len
-- because this one doesn't care the [space] on the right side.
SET @LoopDone = 1
SET @LenText = 0

WHILE @LoopDone = 1
BEGIN
SET @LenText = @LenText + 1

-- We read one char each time to count exactly how many characters it has.
SET @Char = SUBSTRING(@Text, @LenText, 1)

-- If @Char is NULL, then we have done.
IF ASCII(SUBSTRING(@Char, 1, 1)) IS NULL
BEGIN
-- Flag the loop to stop
SET @LoopDone = 0
-- We need to backward one char because the last position was in void.
SET @LenText = @LenText - 1
END
END
--************************************************** *************

RETURN @LenText
END
Apr 18 '07 #1
0 1188

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2743
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__...
8
2776
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
4
2230
by: firegun9 | last post by:
Hello everyone, here is my program: /////////////////////////////// #include <iostream> using namespace std; void multi(double* arrayPtr, int len){ for(int i=0; i<len; i++)...
17
1989
by: Matt Kruse | last post by:
Perl's map() function is a powerful shortcut to accomplish many "loop over an array and do X" operations. Below is a quick hack to simulate similar functionality. I've used it a few times and find...
78
4879
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only...
16
3144
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
2
3733
by: CFAN | last post by:
I have written a variable parameter function: APR_DECLARE_NONSTD(apr_status_t) sas_strcat(char *buffer,size_t * buffer_len ,... ) { char *cp, *argp; apr_size_t saved_lengths; apr_size_t...
5
3587
by: mad.scientist.jr | last post by:
According to http://www.quirksmode.org/js/forms.html you need to look through a radio button's members to find the value: I tried writing a reusable function to return the value, see code at:...
13
3572
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.