SQL Server bug set: "user-defined functions and group"

Source: Internet
Author: User

/** = ** 1. An error occurred while using the custom function for group by. ** = **/
-- A simple function
Create Function f_str (@ STR sysname, @ I INT)
Returns char (1)
As begin
Return (substring (@ STR, @ I, 1 ))
End
Go

-- Below is the test

-- Define test data
Declare @ t table (name sysname)
Insert into @ T values ('abcd ')

-- If group by exists, the result is incorrect.
Select a = DBO. f_str (name, 1), B = DBO. f_str (name, 2)
From @ t
Group by DBO. f_str (name, 1), DBO. f_str (name, 2)

-- The result is correct if no group by exists.
Select a = DBO. f_str (name, 1), B = DBO. f_str (name, 2)
From @ t
Go

-- Delete the User-Defined Function
Drop function f_str

/* -- Test Result
A B
--------
A

(The number of affected rows is 1)

A B
--------
A B

(The number of affected rows is 1)
--*/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.