Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 eliminate last value

Author  Topic 

sqldev6363
Yak Posting Veteran

54 Posts

Posted - 2009-01-13 : 13:56:37
hi,

i have value like this when i am displaying

(a,b,c,d,a)

How to eliminate the last value i.e; (,a) and i want the result like this

(a,b,c,d)

can any one help me

dev

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-13 : 14:06:26
Use DISTINCT or a GROUP BY.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sqldev6363
Yak Posting Veteran

54 Posts

Posted - 2009-01-13 : 14:09:29
i cant use group by at there. can we use any function to delete the last comma and last value.

quote:
Originally posted by tkizer

Use DISTINCT or a GROUP BY.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog




dev
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-01-13 : 15:07:25
[CODE]
DECLARE @IN_STR VARCHAR(255)
SET @IN_STR = 'a,b,c,d,a'

SELECT REVERSE(SUBSTRING(REVERSE(@IN_STR), CHARINDEX(',', REVERSE(@IN_STR)) + 1, LEN(@IN_STR)))
[/CODE]
Go to Top of Page

sqldev6363
Yak Posting Veteran

54 Posts

Posted - 2009-01-13 : 20:17:26
Thanks alot, It was very helpful to me

quote:
Originally posted by rohitkumar

[CODE]
DECLARE @IN_STR VARCHAR(255)
SET @IN_STR = 'a,b,c,d,a'

SELECT REVERSE(SUBSTRING(REVERSE(@IN_STR), CHARINDEX(',', REVERSE(@IN_STR)) + 1, LEN(@IN_STR)))
[/CODE]



dev
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-13 : 23:54:00
is it always last value alone you've remove?
Go to Top of Page
   

- Advertisement -