select left('Hello World /Ok',charindex('/','Hello World /Ok')-1)
Hello World
That works fine.
However I got an error message:
select left('Hello World Ok',charindex('/','Hello World Ok')-1)
Instead of:
'Hello World Ok'
I get:
Server: Msg 536, Level 16, State 3, Line 1
Invalid length parameter passed to the substring function.
Microsoft Doc incorrectly says:
"LEFT ( character_expression , integer_expression )
integer_expression
Is a positive whole number. If integer_expression is negative, a null
string is returned."
Is there an easier solutoin using left or any other string function
instead of using a case statement?
Also, charindex('/','Hello World Ok') should return NULL instead 0 so
that we can use isnull function.
Thanks. 2 7985
On 3 Nov 2006 02:45:44 -0800, ot*******@yahoo.com wrote:
(snip)
>Microsoft Doc incorrectly says: "LEFT ( character_expression , integer_expression ) integer_expression Is a positive whole number. If integer_expression is negative, a null string is returned."
Hi othellomy,
Your copy of Books Online must be outdated, then. Here's what my version
says:
"integer_expression
"Is a positive integer that specifies how many characters of the
character_expression will be returned. If integer_expression is
negative, an error is returned. integer_expression can be of
type bigint."
>Is there an easier solutoin using left or any other string function instead of using a case statement? Also, charindex('/','Hello World Ok') should return NULL instead 0 so that we can use isnull function.
You can use NULLIF to change the 0 to NULL yourself:
SELECT LEFT ('Hello World Ok',
NULLIF (CHARINDEX('/','Hello World Ok'), 0) - 1);
--
Hugo Kornelis, SQL Server MVP
Thanks :)
Hugo Kornelis wrote:
On 3 Nov 2006 02:45:44 -0800, ot*******@yahoo.com wrote:
(snip)
Microsoft Doc incorrectly says:
"LEFT ( character_expression , integer_expression )
integer_expression
Is a positive whole number. If integer_expression is negative, a null
string is returned."
Hi othellomy,
Your copy of Books Online must be outdated, then. Here's what my version
says:
"integer_expression
"Is a positive integer that specifies how many characters of the
character_expression will be returned. If integer_expression is
negative, an error is returned. integer_expression can be of
type bigint."
Is there an easier solutoin using left or any other string function
instead of using a case statement?
Also, charindex('/','Hello World Ok') should return NULL instead 0 so
that we can use isnull function.
You can use NULLIF to change the 0 to NULL yourself:
SELECT LEFT ('Hello World Ok',
NULLIF (CHARINDEX('/','Hello World Ok'), 0) - 1);
--
Hugo Kornelis, SQL Server MVP
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this
script hoping to animate some div blocks on a page. You can see the
page here: http://www.keymedia.biz/demo.htm
Can anyone...
|
by: Nathan Given |
last post by:
Hello All,
I am trying to debug a broken query. The query uses
Left$(,4) instead of Left(,4).
What is the difference between the Left() and Left$() functions in
Microsoft Access?
Thanks!...
|
by: Agnes |
last post by:
in .net , any left function ??
or I should use Microsoft.VisualBasic.Left(myString, 5)
Thanks
|
by: Jm |
last post by:
Hi all
I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to...
|
by: OutdoorGuy |
last post by:
Greetings,
I have a "newbie" question. I was wondering if there is anything in C#
that corresponds to VB's "Left" function? I simply want to retrieve the
leftmost characters of a string and I...
|
by: sql guy123 |
last post by:
I normally use MS ACCESS vs MS SQL,, which has a left() and right()
function. I need to use MS SQL for this project but I am not familiar
with it. I have read a few books, but can not figure out...
|
by: kellygreer1 |
last post by:
What is a good one line method for doing a "length safe"
String.Substring?
The VB classes offer up the old Left function so that
string s = Microsoft.VisualBasic.Left("kelly",200)
// s will =...
|
by: =?Utf-8?B?R3JlZw==?= |
last post by:
I have two questions with regards to the LEFT function.
I ran into a problem with the LEFT function today. I knew it was a valid
Function, but when I tried to use it, it was getting interpreted...
|
by: yalbizu |
last post by:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int NO_OF_STUDENTS=20;
struct studentType
{
string studentFName;
string studentLName;
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |