| |

VerySource

 Forgot password?
 Register
Search
View: 1328|Reply: 5

Ask for a sql statement

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-16 11:00:01
| Show all posts |Read mode
A varchar field aa of table ttt; its value: 2145, 21235, etc.,
I want to select the value from the 2nd position to the end, such as:
select *... from ttt
aa
145
1234 (Don't leave the first ‘2’)
Reply

Use magic Report

1

Threads

23

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-12-16 11:15:02
| Show all posts
select stuff(aa,1,1,'') from tt
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-12-16 21:30:01
| Show all posts
select right(aa,len(aa)-1) from tt
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-12-16 23:00:02
| Show all posts
declare @t table(id int)
insert @t select 2145
insert @t select 21235
select stuff(id,1,1,'') from @t

     
  The first '1' in the stuff function is replaced from the first digit of the ID, the latter '1' is the length of the replacement from the first digit, and the following ``is the replacement
================================
145
1235


Is that so? Isn't that the case in the post?
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-12-16 23:15:01
| Show all posts
Upstairs
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-12-17 11:30:01
| Show all posts
STUFF
Delete characters of the specified length and insert another set of characters at the specified starting point.

grammar
STUFF (character_expression, start, length, character_expression)

parameter
character_expression

An expression composed of character data. character_expression can be a constant, a variable, or a column of character or binary data.

start

Is an integer value that specifies the start position of deletion and insertion. If start or length is negative, an empty string is returned. If start is longer than the first character_expression, an empty string is returned.

length

Is an integer that specifies the number of characters to be deleted. If length is longer than the first character_expression, delete up to the last character in the last character_expression.

Return type
If character_expression is a supported character data type, character data is returned. If character_expression is a supported binary data type, binary data is returned.

Comment
String functions can be nested.

Example
The following example creates and returns a string by deleting three characters from the second position (character b) in the first string (abcdef), and then inserting the second string at the beginning of the deletion.

SELECT STUFF('abcdef', 2, 3,'ijklmn')
GO

Here is the result set:

---------
aijklmnef

(1 row(s) affected)
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