|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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? |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > asp sql select/display help needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|