用于多个select语句的SQL Substring [英] SQL Substring for multiple select statement

查看:122
本文介绍了用于多个select语句的SQL Substring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想为其中一个字段创建一个子字符串,名为



Hi I want to create a sub string for one of the fields called

clip_clip_title





通常剪辑标题名为PRT-12345_2015_06_10_12364.mov现在我只想剪切名称,使其显示为



normally the clip title is called PRT-12345_2015_06_10_12364.mov now i just want to cut the name so it reads

PRT-12345_2015_06_10





但不确定子串如何在多选语句中起作用:







But not sure how substring would work in multi select statement like this:


select CLP_Clip_Name  + ' - ' + CLP_Clip_Title + '</a>'+ ' - ' + CLP_duration from Farmer_CLP_Clips C with (NOLOCK) inner join gl_Tasks_Portal TP on TP.TaskID = TaskID and TP.TaskData_Name = 'FLE_ID' and TP.TaskData_Value = C.FLE_ID order by C.CLP_clip_title





i知道如何做到这一点



i know how to do the simple

select substring('clip_clip_title', 1,15);



哪个有效,但多选择什么是最好的方法呢?

提前谢谢


which works but in multi select whats the best way to do this?
Thanks in advance

推荐答案

如果它们的格式相同时间,你只想要每个名字的前15个字符,然后用 SUBSTRING('clip_clip_title',1,15)替换 CLP_Clip_Title 将会这样做。

如果你想要更复杂的东西(比如基于标题中最后一个_的位置的可变长度子字符串)那么定义你自己的SQL函数: https://technet.microsoft.com/en-us/library/ aa214363(v = sql.80).aspx [ ^ ]并将SUBSTRING调用替换为。
If it's the same format each time, and you only want the first 15 characters of each name, then just replacing CLP_Clip_Title with SUBSTRING('clip_clip_title', 1,15) will do it.
If you want anything more complex (such as a variable length substring based on the location of the last "_" in the title) then define your own SQL function: https://technet.microsoft.com/en-us/library/aa214363(v=sql.80).aspx[^] and replace the SUBSTRING call with that.


只需替换

Simply replace
CLP_Clip_Title 



with


with

substring('clip_clip_title', 1,15)


应该是

It should be
select substring(clip_clip_title,1, 20) from Farmer_CLP_Clips



参考: https: //msdn.microsoft.com/en-us/library/ms187748.aspx [ ^ ]


这篇关于用于多个select语句的SQL Substring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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