SQL GUID在tojson查询中变为大写

问题描述 投票:0回答:2

SQL Server以大写形式返回所有SQL_GUID数据类型。但是默认情况下,我需要用小写字母。

我必须以Json格式返回数据查询,以便在有角度的前端和大写的Guid中使用,必须与相同的Guid在小写中进行比较,但是此比较的结果为false。

SQL Server是否有一种方法可以在不使用内置SQL下层功能的情况下以小写形式返回Guid?

javascript sql-server guid
2个回答
0
投票

GUID基本上是一个16字节的二进制值。没有二进制值(或整数)之类的大写或小写项目。您可以使用ToUpper或ToLower使它们看起来像您想要的样子。

至SQL Server中的大写字母

SELECT UPPER ('8B94A1DA-1956-4D2E-A3A3-30CC52F589F9');

在SQL Server中为小写字母

SELECT LOWER ('8B94A1DA-1956-4D2E-A3A3-30CC52F589F9');

到大写字母成角

'8B94A1DA-1956-4D2E-A3A3-30CC52F589F9'.toUpperCase( );

到小写的小写字母

'8B94A1DA-1956-4D2E-A3A3-30CC52F589F9'.toLowerCase( );

-3
投票

是,您可以在不使用内置SQLlowerfunction的情况下进行操作。这是从castvarchar的方法:

cast(MyUniqueIdenfifierColumn as varchar(36))

现在,假设您有一个varchar(36)作为@input,则可以执行以下操作

declare output as varchar(36);
declare c as varchar(1);

select @output = '';

declare @i int;

select @i = 0;

while @i < len(@input)
begin
    select @i = @i + 1

    select @c = substring(@input, @i, 1);

    if @c = 'A' begin select @output = @output + 'a'; end;
    if @c = 'B' begin select @output = @output + 'b'; end;
    if @c = 'C' begin select @output = @output + 'c'; end;
    if @c = 'D' begin select @output = @output + 'd'; end;
    if @c = 'E' begin select @output = @output + 'e'; end;
    if @c = 'F' begin select @output = @output + 'f'; end;
    if @c = 'G' begin select @output = @output + 'g'; end;
    if @c = 'H' begin select @output = @output + 'h'; end;
    if @c = 'I' begin select @output = @output + 'i'; end;
    if @c = 'J' begin select @output = @output + 'j'; end;
    if @c = 'K' begin select @output = @output + 'k'; end;
    if @c = 'L' begin select @output = @output + 'l'; end;
    if @c = 'M' begin select @output = @output + 'm'; end;
    if @c = 'N' begin select @output = @output + 'n'; end;
    if @c = 'O' begin select @output = @output + 'o'; end;
    if @c = 'P' begin select @output = @output + 'p'; end;
    if @c = 'R' begin select @output = @output + 'r'; end;
    if @c = 'S' begin select @output = @output + 's'; end;
    if @c = 'T' begin select @output = @output + 't'; end;
    if @c = 'U' begin select @output = @output + 'u'; end;
    if @c = 'V' begin select @output = @output + 'v'; end;
    if @c = 'W' begin select @output = @output + 'w'; end;
    if @c = 'X' begin select @output = @output + 'x'; end;
    if @c = 'Y' begin select @output = @output + 'y'; end;
    if @c = 'Z' begin select @output = @output + 'z'; end;
    if len(@output) < @i begin select @output = @output + @c end;
end

自然,您可以在存储的function中使用它。但是,当有用于此目的的库function时,我看不到为什么要执行上述实现。如果仅对内置SQL Server库有问题,也可以在客户端使用toLowerCase Javascript函数。

© www.soinside.com 2019 - 2024. All rights reserved.