Monday, March 12, 2012
Getting Paragraph Count
I need to get a paragraph count of text
1. Pasted into a SQLServer VARCHAR field from Word, and also
2. Entered directly into a SQLServer VARCHAR field entered via an Access ADP
textbox
I tried using
CHARINDEX (ColumnName, CHAR(10),1)
CHARINDEX (ColumnName, CHAR(13) ,1)
CHARINDEX (ColumnName, ' ', 1)
to find the first instance of a blank line, but all returned zero.
Is there a way to count the paragraphs, i.e. blank lines between paragraphs?
Once I know how to find the blank lines, I can loop through text to find all
occurences.
Thanks.
AlanNEVER MIIND!
I had expression order reversed!
Alan
"Alan Z. Scharf" <ascharf@.grapevines.com> wrote in message
news:ulLxGNQUGHA.5172@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I need to get a paragraph count of text
> 1. Pasted into a SQLServer VARCHAR field from Word, and also
> 2. Entered directly into a SQLServer VARCHAR field entered via an Access
ADP
> textbox
> I tried using
> CHARINDEX (ColumnName, CHAR(10),1)
> CHARINDEX (ColumnName, CHAR(13) ,1)
> CHARINDEX (ColumnName, ' ', 1)
> to find the first instance of a blank line, but all returned zero.
> Is there a way to count the paragraphs, i.e. blank lines between
paragraphs?
> Once I know how to find the blank lines, I can loop through text to find
all
> occurences.
> Thanks.
> Alan
>|||You could try this sort of thing. If you remove all the paragraph dividers
from a piece of text, you can then compare the lengths of the original strin
g
with the new one, to see how much text you removed. Divide it by the length
of the paragraph divider, and you have how many there were. Add one because
you're counting the paragraph-splits, not the paragraphs themselves.
Like this (but obviously you wouldn't have to use variables, you could just
use your column names directly):
declare @.text varchar(8000)
set @.text = 'Here is some text.
Here is a second paragraph.
Here is a third.'
declare @.paragraphdivider char(4)
set @.paragraphdivider = char(13)+char(10)+char(13)+char(10)
declare @.paragraphs int
select @.paragraphs = (len(@.text) - len(replace(@.text,@.paragraphdivider,''))
)
/ len(@.paragraphdivider) + 1
select @.paragraphs
"Alan Z. Scharf" wrote:
> NEVER MIIND!
> I had expression order reversed!
> Alan
>
> "Alan Z. Scharf" <ascharf@.grapevines.com> wrote in message
> news:ulLxGNQUGHA.5172@.TK2MSFTNGP12.phx.gbl...
> ADP
> paragraphs?
> all
>
>
Wednesday, March 7, 2012
getting key just entered
Inserted missing < code></ code> tags (without the
spaces inside). Always include such tags when
including code in your postings. Don't force the
moderators to do this for you. Many readers disregard
postings without the code tags.
**************************************************
Hi
Probably a dumb question but I'm doing an insert into a table with an identity field. How do I get the key back straight after I add it?
This is how I do the addition
SQLString = "Insert into users (username,password,status,campus, ulevel ) values ( @.username, @.password, @.status, @.campus, @.ulevel)"
cmdInsert = new SQLCommand(SQLString, conn)
cmdInsert.Parameters.Add( "@.username", _username)
cmdInsert.Parameters.Add( "@.password", md5Hasher.ComputeHash(encoder.GetBytes(_password)))
cmdInsert.Parameters.Add( "@.status", _status)
cmdInsert.Parameters.Add( "@.campus", _campus)
cmdInsert.Parameters.Add( "@.ulevel", _ulevel )
conn.Open()
cmdInsert.ExecuteNonQuery()
conn.close()
but about now I need the primary key just generated.
Any ideas?
Thanks
ABoldWhat database do you use.|||If you are using SQL server, you can return the value of @.@.identity after the insert.|||I wouldnt use @.@.identity. When you are insert into a table that has a trigger and creates another identity value then you will get the last value generated in any table. Use instead SCOPE_IDENTITY(). It will return the generated value for the current scope.
Morehere...|||Like I said, first we need to know which Db the Poster is using. Then we can decide which way to go. SCOPE_IDENTITY() is only available in SQL 2000 Server and later.|||Yes I'm using SQL Server 2000.
SO I can use SCOPE_IDENTITY() thanks I'll look it up.
Thanks
ABold