フルネームの列からファーストネームを返すSQL関数を作成しようとしています。今はLast、Firstの形式で姓を返しています。SQL関数のデバッグ
私の部分文字列関数は、@ index + 2で情報を取得しようとしていますが、最初から始まっています。私は何が間違っているのか分からないのですか?
Create Function dbo.fnGetFirstName (@fullname varchar(100))
Returns Varchar(50)
AS
Begin
--declare the local variable: firstName
Declare @fn varchar(50);
--declare the index variable to find the index of the separator that separates last name from first name
Declare @index int;
--get the separator index value
SET @index = CHARINDEX(',',@fullname);
--check if the default separator (,) exists
IF @index > 0
--if it does, use the substring function to find the First name
BEGIN
Set @fn = SUBSTRING(@fullname, @index+2, LEN(@fullname)[email protected]);
END
不足しているようですEND – McNets
欠けていました。ヒントをありがとう。私はそれを逃したと信じて..... ..... –
私はそれがうまくいくと思う:http://rextester.com/ISBH13610 – McNets