gpt4 book ai didi

SQL 查询修剪字符串

转载 作者:行者123 更新时间:2023-12-02 06:32:29 25 4
gpt4 key购买 nike

我有一个查询如下

select 
First_Name+' '+Middle_Name+' '+Last_Name as studentname,
Batch,
Batch+1 as batch1,
Admtd_Semester,
Program,
Title,
@His_Her as His_Her,
Fathers_Name,
Branch_Name,
Student_Mobile_Number,
Fathers_Mobilenumber,
CONVERT(VARCHAR(10),GETDATE(),110) as date
from
STUDENT_Admission_1212341

在上面的查询中,batch+1 给出的输出是 2014,我只需要 14。我该如何修剪它?

最佳答案

计算余数:

SELECT 2014 % 100

即:

SELECT  First_Name + ' ' + Middle_Name + ' ' + Last_Name AS studentname ,
Batch ,
(Batch + 1 ) % 100 AS batch1 ,
Admtd_Semester ,
Program ,
Title ,
@His_Her AS His_Her ,
Fathers_Name ,
Branch_Name ,
Student_Mobile_Number ,
Fathers_Mobilenumber ,
CONVERT(VARCHAR(10), GETDATE(), 110) AS date
FROM STUDENT_Admission_1212341

关于SQL 查询修剪字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30890242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com