sql - Database character limit on the end of word? -


ok, know can limit size of characters of table field while fetching, of times split comes in middle of word:

select id, title, left(contents, 300) contents posts 

now, possible make split come after word (at space)?

thank you

if using sql server, can like:

select id, title,        left(contents,             (case when charindex(contents, ' ', 300) > 0                   charindex(contents, ' ', 300)                   else 300              end)            ) contents posts; 

in mysql:

select id, title,        left(contents,             (case when locate(' ', contents, 300) > 0                   locate(' ', contents, 300)                   else 300              end)            ) contents posts; 

other databases have similar functions.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -