选择默认字符而不是任何长度的字符串 [英] Select default character instead of string of any length

查看:87
本文介绍了选择默认字符而不是任何长度的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

提前谢谢.

我只想选择"AAA"而不是"RAK"
即如果字符串9为字符串,则选择``AAAAAAAAA''表示9为

例如

"Rak">> ''AAA''
''324544''>> AAAAAA等

请帮忙.

Hi all,

Thanks in advance.

I just want to select ''AAA'' Instead of ''RAK''
i.e. if string of character 9 then select ''AAAAAAAAA'' means 9 As

For e.g.

''Rak'' >> ''AAA''
''324544'' >> ''AAAAAA'' etc.

Please Help.

推荐答案

可能有很多方法,但是一种方法是使用SPACE()函数将所有字符替换为一个空格,然后替换所有字母"A"的空格

There are likely many ways to do it but one way is to replace all characters with a space using the SPACE() function and then replace all the spaces with the letter ''A''

DECLARE @testVar varchar(50); SET @testVar = '12345'
SELECT REPLACE(SPACE(LEN(@testVar)), ' ', 'A')


老兄,使用此代码可能会有所帮助



Hell dude use this code may be help full



DECLARE @position int, @string varchar(100), @FirstStrVal int
DECLARE @position1 int, @string1 varchar(100), @SecondStrVal int
 set @FirstStrVal=0
  set @SecondStrVal=0
SET @position = 1
SET @position1 = 1
SET @string = rtrim(ltrim ('AAAAAA'))
SET @string1 = rtrim(ltrim ('BBBBBB'))

WHILE @position <= DATALENGTH(@string)
   BEGIN
   set @FirstStrVal=@FirstStrVal+( SELECT  ASCII(SUBSTRING(@string, @position, 1)))
   SET @position = @position + 1

 END



 WHILE @position1 <= DATALENGTH(@string1)
   BEGIN
   set @SecondStrVal=@SecondStrVal+(  SELECT  ASCII(SUBSTRING(@string1, @position1, 1)))
  SET @position1 = @position1 + 1

 END



 if(@SecondStrVal>@FirstStrVal)
 begin
 print 'Second String > First String'
 end
 else
 begin
 print  'First String > Second String'
 end


这篇关于选择默认字符而不是任何长度的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆