使用 SQL 从左侧修剪值

trim values from left using SQL(使用 SQL 从左侧修剪值)
本文介绍了使用 SQL 从左侧修剪值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 SQL 值中从左边修剪字符:

I want to trim the characters from the left in my SQL value:

我有以下价值:

ABC0005953

如何从左边修剪 3 个字符的值?我想看:

How do i trim the value 3 characters from the left? I would like to see:

005953

编辑我的值是:

SELECT LEN(TABLE.VALUE)-3)

推荐答案

SELECT SUBSTRING('ABC0005953', 4, LEN('ABC0005953'))

从第四个字符开始并继续.

Start at the fourth character and keep going.

(只是发布作为 RIGHT(...) 解决方案的替代方案.)

(Just posting as an alternative to the RIGHT(...) solution.)

为了回应您的更新,我假设您的意思是您想将上述内容应用于您的表格:

In response to your update, I assume you mean you want to apply the above to your table:

SELECT SUBSTRING(TABLE.VALUE, 4, LEN(TABLE.VALUE))
FROM TABLE

来自您的另一个问题:

我有以下几点:

选择不同

左(GIFTHEADER.pID + GIFTHEADER.PID + '-' + Cast(PAYMENTDETAIL.PLI​​NENO as Varchar),18)

Left(GIFTHEADER.pID + GIFTHEADER.PID + '-' + Cast(PAYMENTDETAIL.PLINENO as Varchar),18)

作为交易参考...

目前我的价值是这样的:

Currently my value looks like this:

ABC0005953ABC0005953

ABC0005953ABC0005953

我想简单地从 GIFTHEADER.pID 中去掉前 4 个字符

I want to simply strip off the first 4 characters from GIFTHEADER.pID

如果您想从 GIFTHEADER.pID 中删除前四个字符,我建议在将值放入组合字符串之前删除它们:

If you want to remove the first four characters from GIFTHEADER.pID, I would recommend removing them before putting the value into your combined string:

SELECT DISTINCT
    LEFT(SUBSTRING(GIFTHEADER.pID, 5, LEN(GIFTHEADER.pID) +
        GIFTHEADER.PID +
        '-' +
        Cast(PAYMENTDETAIL.PLINENO as Varchar),18)
    AS TRANSACTIONREF

这篇关于使用 SQL 从左侧修剪值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)