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 2000 Forums
 Transact-SQL (2000)
 Restric t characters in Select Query

Author  Topic 

DeepakNewton
Starting Member

39 Posts

Posted - 2007-07-05 : 02:19:18
Hello All,

I had a table with comments column which i need to pull the comments from the data

The situation i found here is little bit tough as i new to database programming.....

HIG_tbl_Comments

comment id int
Comments text
dt datetime


"I need to pull the recent Comments (up to 10 comments) from the table, if the Most recent comment has more than 1500 characters then i need to retrive that comment with 1500 characters only (since my front end webpage has the table where it was limited to 1500 characters).

"In any one of the ten comments has got more than 1500 characters then i need to omit that comment and take the next recent one"

it could be helpful if any any one throw some light for this scenario......

thanks in advance

Deepak

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-07-05 : 02:26:37
[code]Select Top 10 comments
from HIG_tbl_Comments
where datalength(comments)<=1500
order by dt desc[/code]

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

DeepakNewton
Starting Member

39 Posts

Posted - 2007-07-10 : 01:33:01
Harsh,
Thanks for your reply .... whether the above query will truncate if the comments column is morethan 1500 characters?
thanks
Murali A
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-10 : 01:45:07
use convert() to convert to varchar with size of 1500.

Harsh misunderstood your requirement. His query will only return comments that is less than 1500 in length.




SELECT TOP 10 comments = CONVERT(varchar(1500), comments)
FROM HIG_tbl_Comments
ORDER BY dt DESC



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

DeepakNewton
Starting Member

39 Posts

Posted - 2007-07-10 : 07:59:06
Thanks khtan
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-07-10 : 08:04:36
Thanks KH.

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

- Advertisement -