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)
 SELECT qry

Author  Topic 

frank.svs
Constraint Violating Yak Guru

368 Posts

Posted - 2007-02-21 : 01:23:40
Dear pals,

I have a table as follows

create table mst_org
(
org_id numeric(18,0),
org_name varchar(20),
org_desc varchar(2000)
)

insert into mst_org values(1,'Oracle','Oracle supply a range of software to manage, share and protect data and information.')
insert into mst_org values(2,'SQL Server','Visit this portal for all the latest news and articles to help you evaluate Microsoft SQL Server 2005 for your data management and analysis needs')
insert into mst_org values(3,'Sybase','Sybase Corp')

I need to display the output as follows. i.e suppose if my org_desc column value length greater than 30 then is should display three ... in the output as follows.
I have tried this using cursor i.e i processes row by row and displayed as follows. But is there a way which can be done using a single SELECT stmt with CASE stmt.


select * from mst_org

1 Oracle Oracle supply a range of so...
2 SQL Server Visit this portal for all t...
3 Sybase Sybase Corp





Any Suggestions is appreciated.

Regards,
franky


harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-21 : 01:27:37
[code]Select
org_id
org_name,
Case When Len(Org_Desc)>30 Then Left(Org_Desc, 27) + '...' Else Org_Desc End as Org_Desc
From mst_org
[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-21 : 01:27:46
[code]
select org_id, org_name, case when len(org_desc) > 30 then left(org_desc, 27) + '...' else org_desc end
from mst_org
[/code]


KH

Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2007-02-21 : 01:30:50
why are u trying this at backend? you can do it in front end, using grid like controls. coz, if u will run this query, u will not get remaining part of data, but in grid u can expand the column, so that it will give u the same effect.

let us know if u r trying something else

thanks,
Mahesh
Go to Top of Page

frank.svs
Constraint Violating Yak Guru

368 Posts

Posted - 2007-02-22 : 07:53:17
Thanks for the help.
Go to Top of Page
   

- Advertisement -