Click here to Skip to main content
15,910,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to create a sub string for one of the fields called

clip_clip_title


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 know how to do the simple
SQL
select substring('clip_clip_title', 1,15);

which works but in multi select whats the best way to do this?
Thanks in advance
Posted
Comments
Geofferz 10-Jun-15 7:21am    
so just to be clear i would like to return select CLP_Clip_Name + '_' + CLP_Clip_Title + CLP_Duration from....

so combining all 4 together to make one filename but i only want to bring back part of the CLP_Clip_title not full title. that make sense?

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.
 
Share this answer
 
v2
Comments
Geofferz 10-Jun-15 8:44am    
Thanks this worked!!
OriginalGriff 10-Jun-15 10:20am    
You're welcome!
Simply replace
SQL
CLP_Clip_Title 

with
SQL
substring('clip_clip_title', 1,15)
 
Share this answer
 
It should be
select substring(clip_clip_title,1, 20) from Farmer_CLP_Clips

Reference: https://msdn.microsoft.com/en-us/library/ms187748.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900