| Author |
Topic  |
|
|
arkiboys
Flowing Fount of Yak Knowledge
1341 Posts |
Posted - 07/06/2012 : 08:28:38
|
Hi, How do I trim off the 'AND' if it is present at the end of the line? Thanks |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8513 Posts |
Posted - 07/06/2012 : 08:33:58
|
declare @line varchar(255) set @line = 'bla and bla and bla and' select reverse(stuff(reverse(@line),1,4,''))
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
arkiboys
Flowing Fount of Yak Knowledge
1341 Posts |
Posted - 07/06/2012 : 08:58:20
|
But what if there is no 'AND' The sql should know if there is or there is not an AND at the end of the line. |
 |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8513 Posts |
Posted - 07/06/2012 : 09:00:39
|
good point:
declare @line varchar(255) set @line = 'bla and bla and bla and' select case when right(@line,4)=' and' then reverse(stuff(reverse(@line),1,4,'')) else @line end
No, you're never too old to Yak'n'Roll if you're too young to die. |
Edited by - webfred on 07/06/2012 09:01:39 |
 |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8513 Posts |
Posted - 07/06/2012 : 09:05:01
|
or this: reverse(stuff(reverse(@line),1,case when right(@line,4)=' and' then 4 else 0 end,''))
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
arkiboys
Flowing Fount of Yak Knowledge
1341 Posts |
Posted - 07/06/2012 : 09:47:45
|
quote: Originally posted by webfred
good point:
declare @line varchar(255) set @line = 'bla and bla and bla and' select case when right(@line,4)=' and' then reverse(stuff(reverse(@line),1,4,'')) else @line end
No, you're never too old to Yak'n'Roll if you're too young to die.
Many thanks |
 |
|
| |
Topic  |
|