| |

VerySource

 Forgot password?
 Register
Search
View: 849|Reply: 6

Ask a function

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-2-5 22:30:01
| Show all posts |Read mode
Is there such a function in sql server, which is to remove the carriage return from the string with carriage return.
as me
      is having a
      Questions to ask "
Becomes "I have a question to ask"
Does anyone know?
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 Germany

Post time: 2020-3-24 13:30:02
| Show all posts
select replace ("I
      is having a
      Question to ask ", carriage return symbol, '')
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-3-24 14:15:02
| Show all posts
select replace ('"I
      is having a
      Question to ask "', carriage return symbol,")
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-3-27 22:15:01
| Show all posts
In sql,
char (10)-newline character
char (13)-carriage return

for example:
declare @ t1 varchar (50)
set @ t1 = 'aaaaa' + char (13) + 'bbbbbb'
print @ t1
result--------------------
aaaaa
bbbbbb


Just replace this carriage return:
declare @ t1 varchar (50)
set @ t1 = 'aaaaa' + char (13) + 'bbbbbb'
set @ t1 = replace (@ t1, char (13), '')
print @ t1

result------------------
aaaaabbbbbb
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 Invalid IP Address

Post time: 2020-3-28 22:30:01
| Show all posts
declare @str varchar (100)
set @ str = 'me
is having a
Questions to ask '

select replace (replace (@str, char (13), ''), char (10), '')
--result
I have a question to ask

(1 row (s) affected)
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-3-29 08:15:01
| Show all posts
Upstairs solution!
Ha ha
Add a little bit ~

declare @ t1 varchar (50)
set @ t1 = 'aaaaa
bbbbbb '
set @ t1 = replace (replace (@ t1, char (13), ''), char (10), '')
print @ t1
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-1 23:30:01
| Show all posts
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
create function [dbo]. [fn_removeChr13Chr10]
(
@str varchar (max) = 'helloworld',
@ IsRemoveChr13 bit = 1,
@ IsRemoveChr10 bit = 1
)
RETURNS varchar (max)
as
begin

--- remove the key char (13) [return] in the string
if @ IsRemoveChr13 = 1
begin
select @ str = replace (@ str, char (13), '')
end

--- remove the key char (10) [line feed] in the string
if @ IsRemoveChr10 = 1
begin
select @ str = replace (@ str, char (10), '')
end

return @str

end
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list