Postingan

Menampilkan postingan dengan label Sybase and SQL Server

How to find Length of String in SQL Server? LEN() Function Example

Gambar
One of the most common task while writing SQL queries or stored procedure is to find the length of String. Since most of the columns are VARCHAR, you often need to find the length before taking any action. In Java, you can find the length of String by using the length() method but how about SQL Server? How will you find the length of String in Microsoft SQL Server in general and Microsoft SQL Server 2016 in particular? Well, you can use the LEN() function to find the length of a String value in SQL Server, for example, LEN(emp_name) will give you the length of values stored in the column emp_name . This method exists from SQL Server 2008 onwards which means you can use this function in SQL Server 2012, 2014, 2016 and latest version of Microsoft SQL Server i.e. SQL Server 2017. Btw, you should remember that this is different than the length of the actual column which you specify while creating table e.g. emp_name VARCHAR(60). To give you an example, you have a column called emp_name VA...

How to Remove Leading/Trailing White Space from a String in SQL Server? LTRIM, RTRIM Example

Gambar
Unlike Java, Microsoft SQL Server 2008, 2012, 2014,  and even the latest version don't have a built-in trim() function, which can remove both leading and trailing space from the given String. But, SQL Server does have two built-in functions LTRIM() and RTRIM() to remove leading and trailing space. The LTRIM() function removes space from the left side of String so you can use it to get rid of leading space, while RTRIM() removes white-space from the right side of String so you can use it to delete trailing space. You can even combine these two methods to create your own TRIM() method in SQL SERVER e.g. LTRIM(RTRIM(column)) will act as a TRIM() method because it removes both leading and trailing space . How to use LTRIM() and RTRIM() in SQL Server You can use LTRIM() and RTRIM function like any other built-in function. You can apply it to a value or a column in SQL query. Here is a couple of example of LTRIM function in Microsoft SQL Server database: // variable declaration DECL...

Database Website to Run and Practice SQL Query Online for FREE - SQLFiddle

Gambar
Other day, I was looking for a website to execute SQL query online, since I have uninstalled Microsoft SQL Server because of memory and CPU constraint and I don't want to install it again, just for executing another query. Also, installing database is pain, it takes time and eats up lots of resources e.g. RAM memory, CPU etc; Given so many database to work with e.g. Oracle, MySQL, Sybase, PostgreSQL and SQLLite, it's not really possible to have all of them in your poor laptop. Fortunately my search leads be to this wonderful site called SQLFiddle, this is what exactly I wanted. This site offers support for lot of popular databases, allows you to build your database schema online and execute SQL query on the fly. I couldn't have asked more, It's a great resource to learn and practice SQL queries online . Apart from many sweet features, it also allows you to share your problem with the community. If you are writing a complex query and stuck in middle, looking for help, yo...