You are hereSql Server

Sql Server


rahul's picture

Trimming a custom character from the end of a T-Sql string

I recently had a situation where I needed to trim a custom character from the right of a string in Sql Server. Although Sql Server provides a RTRIM function, it can only trim spaces from a string.

A quick search over web threw up some interesting results, but all of them were buggy in one way or another. The major problem was that most of them assumed that spaces would not occur in the string itself.

So, I came up with the following solution as a UDF:

rahul's picture

Local Variables in a T-Sql loop are not really local

I found this the hard way out. Local variables in a T-Sql loop in Sql Server are not really local in the strict terms of a block-oriented programming language like C/C++.

e.g. In C++, if you have the following:

int i;
for (i = 0; i<=10; i++)
{
       int *p = NULL;
       if (p == NULL)
          p = new int(1);
       else
          *p = *p + 1;
       printf("%d", *p);

}

rahul's picture

Limiting rows in Sql Server

One problem I have always faced with Sql Server (more so, after I used MySql, and saw that MySql allows this) is to find a way to limit the number of rows being fetched in a SELECT query.