0

Remove the last word while using left in sql query...I weant to avoid broken words while doing so...
My query as follows:

select top 2 tempJobTitle.id,tempJobTitle.JobRefId,tempJobTitle.JobTitle,LEFT (jobmaster.JobDescription2, 330)+'....' as JobDescription,jobmaster.PostedDate from tempJobTitle inner join jobmaster on jobmaster.JobRefId=tempJobTitle.JobRefId where tempJobTitle.Status='Approved' and jobmaster.ClosingDate >= '2013-03-01' order by tempJobTitle.DateofEntry desc

Edited by pritaeas: Added markdown

3
Contributors
8
Replies
31
Views
4 Years
Discussion Span
Last Post by adam_k
0

The only way I can think of right now is to:

  1. Use LEFT
  2. REVERSE the result of 1
  3. Use CHARINDEX on the result of 2 to search for a space
  4. If 3 returns NULL, 0 or 1 use TRIM else continue with 5
  5. Use SUBSTRING with the result of 4 to remove the last (partial) word
  6. REVERSE the result of 5
0

Shouting (all capitals) doesn't help, because it's considered very rude. Trying the functions yourself to see what they do (showing some effort) and then trying to use them to solve your problem helps too. You get help when you show effort.

0

I was hoping he'd show some effort... to get to know the functions and where to look, but alas, stupid me.

Edited by pritaeas

0

I totally agree about OP, but you used 2 reverse, 1 substring, 1 trim, 1 left.
Probably everything is to be used twice if you really meant it about the if - or a case if you want to do it in 1 select.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.