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.
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_Commentscomment 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 commentsfrom HIG_tbl_Commentswhere datalength(comments)<=1500order by dt desc[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
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?thanksMurali A |
 |
|
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_CommentsORDER BY dt DESC KH[spoiler]Time is always against us[/spoiler] |
 |
|
DeepakNewton
Starting Member
39 Posts |
Posted - 2007-07-10 : 07:59:06
|
Thanks khtan |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-07-10 : 08:04:36
|
Thanks KH.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|