报告生成器中的首字母大写

时间:2022-06-16 16:52:00

I am writing a report using report builder and the one of the filed value of the data set is in upper-case I want to capitalize first letter of this data field value in the text box. Please let me know if you could help.

我正在使用报告生成器编写报告,并且数据集的字段值之一是大写的我想在文本框中大写此数据字段值的第一个字母。如果你能提供帮助,请告诉我。

Thanks Yogi

1 个解决方案

#1


1  

I'm assuming you're using a query from the database to fetch your data through a connection object. Based on what you've said here, a reasonable approach would be:

我假设您正在使用数据库中的查询来通过连接对象获取数据。根据您在此处所说的,合理的方法是:

SELECT UPPER(LEFT([FIELD],1))+LOWER(SUBSTRING([FIELD],2,LEN([FIELD])))

If you have more than one word in your data, you will have to create a UDF to handle to pascal casing:

如果数据中有多个单词,则必须创建一个UDF来处理pascal大小写:

CREATE FUNCTION [dbo].[pCase] 
( 
    @strIn VARCHAR(255) 
) 
RETURNS VARCHAR(255) 
AS 
BEGIN 
    IF @strIn IS NULL 
        RETURN NULL 

    DECLARE 
        @strOut VARCHAR(255), 
        @i INT, 
        @Up BIT, 
        @c VARCHAR(2) 

    SELECT 
        @strOut = '', 
        @i = 0,  
        @Up = 1 

    WHILE @i <= DATALENGTH(@strIn) 
    BEGIN 
        SET @c = SUBSTRING(@strIn,@i,1) 
        IF @c IN (' ','-','''') 
        BEGIN 
            SET @strOut = @strOut + @c 
            SET @Up = 1 
        END 
        ELSE 
        BEGIN 
            IF @up = 1 
                SET @c = UPPER(@c) 
            ELSE 
                SET @c = LOWER(@c) 

            SET @strOut = @strOut + @c 
            SET @Up = 0 
        END 
        SET @i = @i + 1 
    END 
    RETURN @strOut 
END 

And then utilise the function like so:

然后利用这样的功能:

SELECT DBO.PCASE([FIELD])

#1


1  

I'm assuming you're using a query from the database to fetch your data through a connection object. Based on what you've said here, a reasonable approach would be:

我假设您正在使用数据库中的查询来通过连接对象获取数据。根据您在此处所说的,合理的方法是:

SELECT UPPER(LEFT([FIELD],1))+LOWER(SUBSTRING([FIELD],2,LEN([FIELD])))

If you have more than one word in your data, you will have to create a UDF to handle to pascal casing:

如果数据中有多个单词,则必须创建一个UDF来处理pascal大小写:

CREATE FUNCTION [dbo].[pCase] 
( 
    @strIn VARCHAR(255) 
) 
RETURNS VARCHAR(255) 
AS 
BEGIN 
    IF @strIn IS NULL 
        RETURN NULL 

    DECLARE 
        @strOut VARCHAR(255), 
        @i INT, 
        @Up BIT, 
        @c VARCHAR(2) 

    SELECT 
        @strOut = '', 
        @i = 0,  
        @Up = 1 

    WHILE @i <= DATALENGTH(@strIn) 
    BEGIN 
        SET @c = SUBSTRING(@strIn,@i,1) 
        IF @c IN (' ','-','''') 
        BEGIN 
            SET @strOut = @strOut + @c 
            SET @Up = 1 
        END 
        ELSE 
        BEGIN 
            IF @up = 1 
                SET @c = UPPER(@c) 
            ELSE 
                SET @c = LOWER(@c) 

            SET @strOut = @strOut + @c 
            SET @Up = 0 
        END 
        SET @i = @i + 1 
    END 
    RETURN @strOut 
END 

And then utilise the function like so:

然后利用这样的功能:

SELECT DBO.PCASE([FIELD])

相关文章