I have a SQL column with a length of 6. Now want to take only the first char of that column. Is there any string function in SQL to do this?
SQL Server LEFT() Function The LEFT() function extracts a number of characters from a string (starting from left).
You can use LEN() or LENGTH()(in case of oracle sql) function to get the length of a column. SELECT LEN(column_name) FROM table_name; And you can use SUBSTRING or SUBSTR() function go get first three characters of a column.
LEFT(colName, 1)
will also do this, also. It's equivalent to SUBSTRING(colName, 1, 1)
.
I like LEFT
, since I find it a bit cleaner, but really, there's no difference either way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With