Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 5th, 2004, 10:48 PM
bbd bbd is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 bbd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question asp sql select/display help needed

Website is using asp and is connected to a SQL Database. There are a whole bunch of articles in the DB and I want to be able to display a preview of the article. Eg. the first 50 words or 200 characters (or whatever). Below is the current code that displays the full article.

I need to retain this code for displaying the full article but on another section of the site I want to display a preview (50 words/200 characters ish)

Any help would be much appreciated. I can be emailed on it@scc.edu.au. Thanks

The current Display Statement (displays the full article)
<%=(Article_Author.Fields.Item("Article_Content").Value)%>

The current select Statement (SQL view)
CREATE VIEW Article_Author_View
AS
SELECT Document.HTML_Key AS Article_id, Document.Title AS Article_title, Authors.Author_Name, Authors.Author_ID,
Document.Document AS Article_Content, Authors.Author_Email, Authors.Author_Given, Document.TifFile,
Document.GifFile, Document.PDF_String
FROM Document INNER JOIN
Authors ON Document.Author_ID = Authors.Author_ID

Reply With Quote
  #2  
Old June 10th, 2004, 08:33 AM
RvCNet RvCNet is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Holland
Posts: 37 RvCNet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 18 sec
Reputation Power: 5
in ASP you can use something like:
Left(Article_Author.Fields.Item("Article_Content").Value, 200)
Or in SQL something like:
SELECT LEFT (Article_Content, 200) FROM ......

In both cases, you should only see the first 200 chars.

I hope it helps
Good luck.

Reply With Quote
  #3  
Old June 10th, 2004, 09:27 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 22 m 16 sec
Reputation Power: 443
do this...
Code:
SELECT ArticleID, ArticleTitle, LEFT(ArticleStory, CHARINDEX(' ', ArticleStory, 200)) as 'Body' 
FROM TableName

The solution above is okay, but if the 200th character is the middle of a word, it will cut it off.

This solution will return the first 200 characters, but if the 200th character is a letter in a word, it will continue forward until it finds the end of the word.

Reply With Quote
  #4  
Old November 25th, 2004, 10:41 AM
hendriku hendriku is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 hendriku User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Memnoch,

Your solution worked for me, but not all the way. Somehow some records are not being displayed while others do.

Returned strings with 73, 60 and 58 characters do get displayed while two strings with 58 and 54 characters don't get displayed. I can't find out why. Here they are:

1: Interne informatievoorziening over inhoud en kwaliteit db op poten zetten (73 ch and displayed)
2: Kwaliteit NAW verhogen en informatie in database verdiepen (58 ch and not displayed)
3: Internet toegang van rapportages en data SQL Server creeeren (60 ch and displayed)
4: this function returns a speciufied number of character (54 ch not displayed)
5: Deze notitie is alleen maar even om te kijken of het werkt (58 ch and displayed)

I've have set the following condition:
If CharCount (the var with string) > 50 then shorten it with your solution
elseif CharCount =< 50 then display full string

Any ideas how to solve this?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > asp sql select/display help needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway