Pages

String Functions in SQL Server

1. LEN ( string or expression )

we know this function which retrives the length of the data in the column.

Consider a query,

SELECT LEN('sample text')

returns value 11

This function will work for Data types varchar(max), nvarchar(max) or varbinary(max), which return int or bigint value.

2. DATALENGTH ( expression )

This is function similar to LEN, but it is especially useful with text, image and ntext Data Types and also for varchar, varbinary and nvarchar Data Types.

The DATALENGTH of NULL is NULL.

we can use the LEN to find the length of string expression after casting or converting it to varchar, please note, using this may truncate real values.

VB .NET New Logical Operators AndAlso and OrElse

Vb.Net has introduced two new logical operators AndAlso and OrElse.

These operators basically works like And and Or of VB6.0

The speciality of this the performance of the operators, consider a statement involving two conditions.

if ((2>3) AndAlso (4>3)) Then
'...
'Body of the section
'...
End If


Here, In the statement the first condition is false, let the second condition may true or false, the if block will not go to the then section , since we are using And operator. so either checking or not checking the second condition doesn't have a effect here, so the New Operator AndAlso stops checking the second condition and proceeds. this increases the performance in Logic and efficiency in Code.

Similarly the operator OrElse works in the same manner.

if ((2<3) OrElse (4>3)) Then
'...
'Body of the section
'...
End If


Here, the first condition is true, so no verification of second condition is not required as we are using the Or operator, so it skips the second condition and proceeds.

Thanks to the Creators...