Counting Of Occurrences Of A Word In A Text Field

Oct 27, 2003

Finding numbers of occurrences of a string of characters
in a column of TEXT datatype.
DDL of involved table txt:
create table txt (pk int, txtcol text) -- datatype of pk doesn't matter

declare @word varchar(80) set @word='help'
declare @pk int, @count int, @i int, @dl int, @wl int
set @wl=len(@word)
declare abc cursor for select pk from txt
where patindex('%'+@word+'%',txtcol)>0 order by pk
open abc fetch next from abc into @pk
while @@fetch_status=0
begin
select @dl=datalength(txtcol) from txt where pk=@pk
select @i=patindex('%'+@word+'%',txtcol)+@wl from txt where pk=@pk
set @count=1
while @i<@dl
begin
select @count=@count+(len(substring(txtcol,@i,8000))-
len(replace(substring(txtcol,@i,8000),@word,'')))/@wl
from txt where pk=@pk
set @i=@i+8001-@wl
end
select pk=@pk, occurrences=@count
fetch next from abc into @pk
end
close abc deallocate abc
pk occurrences
----------- -----------
1 1

pk occurrences
----------- -----------
2 2

pk occurrences
----------- -----------
3 11
Edit: as suggested-reminded by jsmith8858.

View 7 Replies


ADVERTISEMENT

Counting Occurrences Of A Value

Jul 19, 2007

I have a column in a report with values Y or N or V. In the header, I have to show the number of times each value appeared.



I used RepeatingValue() with IIF() but it's counting all the values as same, e.g., if there are four occurrences of Y, two of N and one of V, I want something like this:



Y Cnt=4, N Cnt=2, V Cnt=1



My assumption was that this will work (white spaces added for readability:



=iif(

Fields!myCol.Value = "Y",

"Y Cnt=" & RunningValue(Fields!myCol.Value, Count, "dsMyDataSet"),

iif(Fields!myCol.Value = "N",

"N Cnt= & RunningValue(Fields!myCol.Value, Count, "dsMyDataSet"),

iif(Fields!myCol.Value = "V",

"V Cnt= & RunningValue(Fields!myCol.Value, Count, "dsMyDataSet"),

"NULL"

)

)

)



Please help.

View 3 Replies View Related

T-SQL (SS2K8) :: Counting Number Of Occurrences?

Sep 23, 2015

I'm trying to figure out how to do the following:

Number of People receiving their second speeding ticket during this time frame

4 Jun 06 -3 Jun 07
4 Jun 07 -3 Jun 08
4 Jun 08 -3 Jun 09
4 Jun 09 -3 Jun 10
4 Jun 10 -3 Jun 11
4 Jun 11 -3 Jun 12

The table would contain historical data and look something like this

CREATE TABLE [dbo].[test](
[person_id] [NCHAR](10) NULL,
[ticket_date] [DATE] NULL,
[ticket] [BIT] NULL
) ON [PRIMARY]
GO

View 9 Replies View Related

Replace One Word With Another In Text Field

Oct 19, 1999

I have a text field that contains multiple words. Is there a way with SQL to relace a single word with another?

for example:

FIELD : CompanyName
DATA : Microsoft Corp.
DATA : IBM Corp.
etc...
DATA : Canon Corp. of America

How can I run a routine to just REPLACE "Corp." with "Corporation" ?

Thanks for your help!
Scott

View 1 Replies View Related

Split Text Field - Display 1st Or 2nd Word

Sep 24, 2012

In SQL SErver 2008, I have a text column. I need to display either 2nd word in the text column or 1st word in the text column based on certain conditions.

How shall i display either 2nd word or 1st word from a text field.

View 1 Replies View Related

Counting Bit Field

Dec 15, 2007

Hi Guy's,

New to servers,

I'm trying to change my Access query into a Server View but I am having trouble counting my Yes/No field that has become a bit field [RevReq].

This is what I have tried but [RevReq] gives me the same count as the [PayNumber] field which is counting the records in the table:


SELECT TOP (100) PERCENT StaffListSQL.dbo.StaffList.Level1, StaffListSQL.dbo.StaffList.[Group], StaffListSQL.dbo.StaffList.Discipline AS Disc,
COUNT(dbo.tblReviews.PayNumber) AS Staff, COUNT(dbo.tblReviews.RevReq) AS Rev, COUNT(dbo.tblReviews.AppStatus) AS RevApp
FROM dbo.tblReviews RIGHT OUTER JOIN
StaffListSQL.dbo.StaffList ON dbo.tblReviews.PayNumber = StaffListSQL.dbo.StaffList.[Pay Number]
GROUP BY StaffListSQL.dbo.StaffList.[Group], StaffListSQL.dbo.StaffList.Discipline, StaffListSQL.dbo.StaffList.Level1
ORDER BY StaffListSQL.dbo.StaffList.Level1

Here is what is returned:

Acute Clyde Acute Services PTB 16 16 0
Acute Clyde Acute Services S&P 0 0 0
Acute Diagnostic Services A&C 16 16 0
Acute Diagnostic Services AFC 15 15 0
Acute Diagnostic Services AHP 482 482 0
Acute Diagnostic Services ASC 338 338 0
Acute Diagnostic Services MAINT 1 1 0
Acute Diagnostic Services MED 0 0 0
Acute Diagnostic Services MISC 0 0 0
Acute Diagnostic Services NURSE - Q 765 765 0
Acute Diagnostic Services NURSE - U 62 62 0
Acute Diagnostic Services PTB 85 85 0
Acute Diagnostic Services S&P 10 10 0
Acute Emergency Care & Medical Specialties NULL 1 1 0
Acute Emergency Care & Medical Specialties A&C 48 48 0

Hope this makes sense and thanks in advance.

View 5 Replies View Related

Counting First/One Instance Of Field

Dec 5, 2007

I'm trying to only count the first instance of a field value for one specific field in a table. Example:

ColA ColB ColC
John Smith xyz
John Smith abc
John Smith xyz
John Smith abc
Larry Smith abc
Larry Smith xyz

The correct count would be 4 because we only count "John Smith xyz" and "John Smith abc" once each, but we count every instance thats unique. Seems simple enough but I can't seem to put it together. Thanks in advance!

View 5 Replies View Related

Counting Based On A Field Combination

Jul 23, 2005

Having a brainfart....I need a query that returns a record count, based on two distinct fields.For example:Order Revision Customer001 1 Bob001 2 Bob002 1 John003 1 John004 1 John005 1 Bob006 1 Bob006 2 BobThe query on the above data should return a count of orders, regardless ofthe revision numbers (each order number should only be counted once).So WHERE Customer = 'Bob', it should return OrderCount = 3TIA!Calan

View 2 Replies View Related

Counting Field Totals As A Formula

Jul 23, 2005

Hi,I'm trying to count field login totals for users which updates another fieldin another table. Which is the most efficient method?I don't want to use a standard query as it will take too long if there are1000 users per company each with 1000 plus logins.I was thinking in terms of either a function, or a formula (using the built-in formula field within mssql).the query though (as its the only way which i'm familiar) is:SELECT SUM(NumberOfLogons) AS TotalLogonsFROM EmployerProfileDB39WHERE (CompanyName = x) AND (EmployerID = y)how would i write this as a formula or as a function?

View 1 Replies View Related

T-SQL (SS2K8) :: Counting Decimal Places In A Float Field

Jul 3, 2014

I have a table with three columns: UniqID, Latitude, and Longitude.

I need to write a query to identify when the latitude has more than 6 decimal places past the decimal. Same with Longitude. Values in these attributes can be a negative number. These fields are FLOAT.

View 7 Replies View Related

Changing Word Doc Text Using T-SQL

Sep 13, 2007



Hi,
i was checking books online and run into the sp_OAxxxx stored procs that can give us access to a OLE Object.
I am currently developing a VB.Net app that uses a word template to create word documents. So, for example ,i we suppose that the template is :
-----Template start -------
This document was created by <!_author_> on <!_date_>
-----Template end --------
then, the created document would be :
-----Created doc start -------
This document was created by justsarter on 09/13/2007
-----Created doc end --------

All the data are fetched from a database and i have to make muptiple calls to it ,not to mention opening and closing word.application object.

I wonder if that kind of text manipulation in the document can be performed on the server using an SP
Thx
theodore

View 1 Replies View Related

Word Doc In Image Field Type

Feb 25, 2005

Hi,

I was wondering if someone can help me with is problem.

I have uploaded word docs to the db which is fine. The problem is viewing. I can view then as word documents but the boss does not want the files opened in word.

Is it possable to retrieve the file from from the db and put into say a textbox or lable.

I can see the letter P using this code

Dim Doc() As Byte = New Byte(Convert.ToInt32(0)) {}
Dim bytesReceived As Long = DBContent.GetBytes(0, 0, Doc, 0, Doc.Length)

Dim encoding As ASCIIEncoding = New ASCIIEncoding
lblTest.Text = encoding.GetString(Doc, 0, Convert.ToInt32(bytesReceived)).ToString

Can any help

Thanks

View 4 Replies View Related

Adding A Word To Existing Value Of A Field

Sep 17, 2007

Hi!
I want to add a word to a value if the value already exists in that field. How to do this? Please help me. In detail, i have 'id', 'name' and 'info' three columns in one Data Table. When I inserted one value to id field, if the value already exists it should add a word to that value and it should get inserted. Please help me to do this?
Thanks in advance!

View 5 Replies View Related

Searching For A Word On Each Table On Very Field

Feb 9, 2006

Hi everybody,

is it possible using SQL Server search for a word on each
table on each field?

Thanks

Fabio

View 6 Replies View Related

Criteria; Search Any Word In Field

May 26, 2004

I am trying to set up a query that will allow the user to input a string, and the search will match ANY word in that string. Currently, I have it configured so that the search will only match the exact string that the user inputs. I have google searched for the answer, but no luck yet. Any ideas?

View 9 Replies View Related

How To Search Text In A Word Document ?

Nov 24, 2005

I'm designing a Job Recruitment Website, in which the admin person searches for the right candidate for the job using certain keywords . Each jobseeker will be uploading  his CV (ms word doc) during registration .How can i search for keywords in  the word documents. I just want the candidate reference once i found keyword match in the word docs.I heard about the indexing and blobs in sql server? But dont know much about it Are these the only solutions ?Is there any better approach for this ?Any help will be greatly appreciated

View 4 Replies View Related

Reporting Services :: Report Builder 2.0 - Counting The Number Of Times A Field Is Completed?

Oct 1, 2015

In report builder 2.0, I cannot determine how to display the number of times a field has been filled out when a  one to many relationship is involved. I get an error every time I use two aggregates.

ID, Symptom_ID
1, 111
2, NULL
3, 222
3, 333
3, 444
4, NULL
5, 666

The result should be 3 out of 5 records... Or even better displayed as a percentage of the total 60%

View 2 Replies View Related

Find Exact Word In Full-Text Search

Oct 3, 2007

Hi,
I have the fields like this.

Session1               Session2                  Session3   Session4----------------------------------------------------------------------------------------- SQL Server-Part1    SQL Server-Part2      ASP.Net    CSS
C#                         SQL Server-Part3    ASP.Net    Javascript 
I have set the Full-Text to all the columns. For searching i wrote the below query
SELECT * FROM <TABLE NAME> WHERE CONTAINS(*,'"SQL Server-Part1"') 
My Result expectation is: The  First Record should come. But the result of the query bring the two records. It see the "SQL Server" string also. I need to find the exact word. How to do it? Please answer me as soon as possible. Ganesh. 
 

View 6 Replies View Related

How To Compare Two Word Documents Using Full Text Search?

Mar 19, 2006

can we use full text search and mining algorithms to comapre two word or text documents to find out if they are similar
please help.
thaks for reading

View 3 Replies View Related

SQL 2012 :: How To Count Instances Of Each Word Throughout Comments Field Across The Table

Oct 21, 2015

I have to count the number of instances of each word in the Comments column throughout the table using SQL Server. Eg:

Row# Comments
1 I like working on SQL
2 I enjoy sleeping and like watching TV

So the output should be :

Word Count
I 2
like 2
working 1
on 1
SQL 1
.......

Any way to get this count using MS SQL?

View 5 Replies View Related

In A Real Pinch With FreeTextBox / Paste From Word / Ntext Field In SQL2k!

Apr 10, 2005

I am in a real squeeze here.  I am working on my first ASP.NET project here and I am having some big problems with a content management aspect of this so far.  I have a freetextbox control that my users want to be able to paste out of Word and save the content to a MSSQL Database.  Well this was working great until I found out that I have a 4000 character limitation, and most of the pasted data is well over 14000 characters at least.
I've been working on these for about two weeks and just have come to a dead end.  Here's what I had before:  Form with Freetextbox that saved the information in the form to a database by calling a function in a class.vb file, the class file then called a stored procedure using parameters.  Similiarly the display page loaded with a record id, and fired off a function stored in a class file, using stored procedures and using output parameters to I could assign the returned values to label fields etc.  This has completely gone down the toilet since i had to change to text field to accomodate the larger text sizes.  I have found some resources about chunking out to the file system, but I really don't want to do that, I just want it to display the information out on a web page, and I have been scouring google for weeks!  Can someone tell me if this the wrong approach?  How do I go about storing / retrieving HTML in an ntext database field just like these forums?  I am completely stumped!

View 2 Replies View Related

Transact SQL :: Return Field When A Field Contains Text From Another Field

Aug 25, 2015

I'm new to SQL and I'm trying to write a statement to satisfy the following:

If [Field1] contains text from [Field2] then return [Field3] as [Field4].

I had two tables where there were no matching keys. I did a cross apply and am now trying to parse out the description to build the key.

View 8 Replies View Related

Searching For A Word In A Text File And Retuning It Using Script Taks In Ssis

May 10, 2007

does any one how to search for a word in a text file and return it back using the script task in ssis?



the file may contain data like this



POSITION SMSMSS20051230000

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230

S ,,751600 ,,20051110,,20051230,20051230



what i am looking for is to be able to parse and get the date which is present in the first line "POSITION SMSMSS20051230000" as "20051230"

and then return that as a variable ..



Thanks for any help in advance



smathew







View 3 Replies View Related

Problem With Text Field: Text Input Too Long, Weird Characters

May 15, 2006

Hi,

Im a programmer for an university webportal which uses php and msssql.
When an user creates a new entry and his text is too long the entry is cut short and weird characters appear at the end of the entry.

For example:
http://www.ttz.uni-magdeburg.de/scripts/test-messedb/php/index.php?option=show_presse&funktion=presse_show_mitteilung&id=333

How can I set the text limit to unlimited?
Could it be something else?
Is there a way of splitting an entry to several text fields automatically?


Thanks in advance for any help you can give me,
Chris

View 3 Replies View Related

SQL 2012 :: Text Qualifier Inside A Text Qualified Field

Mar 12, 2015

In SQL 2005 if i was trying to insert some data with a text qualifier inside a text qualified field, it would work, for example:

"Name","ID ","Location","","Comany",""House Name" Road",

In SQL 2012, this fails with the error message, cannot find the text qualifer for field.

To get around this, we are having to import the data into a Dirty Data column of aTEMP table, ID, Dirty Data, Clean data - perform multiple updates and change the text qualifier and ensure they are only changed in the right places so we can keep the ". In this example, we changed the text qualifier to PIPES.

After these updates, we then export the data from CLEAN data back out to CSV, then reimport it into the origional destination table with a new text qualifer.

View 5 Replies View Related

Transact SQL :: Server Text Field Not Returning Full Text

Apr 21, 2015

I have a column in a table that has a type TEXT,when I pull the length of a row it returns 88222 but when I select from that column it dows not show all the text in the result set.

View 3 Replies View Related

Access Memo Field To SQL Server Text Field

Nov 19, 2006

Hi,

I'm importing an Access database to SQL Server 2000.
The issue I ran into is pretty frustrating... All Memo fields that get copied over (as Text fields) appear to be fine and visible in SQL Server Enterprise Manager... except when I display them on the web via ASP - everything is blank (no content at all).

I didn't have that problem with Access, so I ruled out the possibility that there's something wrong with the original data.

Is this some sort of an encoding problem that arose during database import?
I would appreciate any pointers.

View 14 Replies View Related

Create Date Field From Substring Of Text Field

Jul 20, 2005

I am trying to populate a field in a SQL table based on the valuesreturned from using substring on a text field.Example:Field Name = RecNumField Value = 024071023The 7th and 8th character of this number is the year. I am able toget those digits by saying substring(recnum,7,2) and I get '02'. Nowwhat I need to do is determine if this is >= 50 then concatenate a'19' to the front of it or if it is less that '50' concatenate a '20'.This particular example should return '2002'. Then I want to take theresult of this and populate a field called TaxYear.Any help would be greatly apprecaietd.Mark

View 2 Replies View Related

MS Access Memo Field To SQL Server Text Field

Aug 20, 2006

Hi all,



i've a reasonable amount of experience with MS Access and less
experience with SQL Server. I've just written an .NET application that
uses an SQL Server database. I need to collate lots of data from around
the company in the simplest way, that can then be loaded into the SQL
Server database.



I decided to collect the info in Excel because that's what most people
know best and is the quickest to use. The idea being i could just copy
and paste the records directly into the SQL Server database table (in
the same format) using the SQL Server Management Studio, for
example.



Trouble is, i have a problem with line feed characters. If an Excel
cell contains a chunk of text with line breaks (Chr(10) or Chr(13))
then the copy'n'paste doesn't work - only the text up to the first line
break is pasted into the SQL Server database cell. The rest is not
pasted for some reason.



I've tried with MS Access too, copying and pasting the contents of a
memo field into SQL Server database, but with exactly the same problem.
I've tried with 'text' or 'varchar' SQL Server database field formats.



Since i've no experience of using different types of databases
interacting together, can someone suggest the simplest way of
transferring the data without getting this problem with the line feeds?
I don't want to spend hours writing scripts/programs when it's just
this linefeed problem that is preventing the whole lot just being
cut'n'pasted in 5 seconds!



cheers

Dominic

View 6 Replies View Related

Export Access Memo Field To SQL Text Field

May 30, 2006

Hi,

Can anyone point me any solution how to export a MEMO field from an Access database to a TEXT field from an MS SQL Server 2000. The import export tool from SQL server doesn't import these fields if they are very large - around 9000 characters.

Thanks.

View 1 Replies View Related

How Can I Parse Text Held In MS SQL 2005 Text Field

Apr 24, 2007

Hi,I been reading various web pages trying to figure out how I can extract some simple information from the XML below, but at present I cannot understand it.
I have a MS SQL 2005 database with which contains a field of type text (external database so field type cannot be changed to XML)The text field in the database is similar to the one below but I have simplified it by remove many of the unneeded tags in the <before> and <after> blocks. I also reformatted it to show the structure (original had no spaces or returns)
For each text field in the SQL table contain the XML I need to know the OldVal and the NewVal.
<ProductMergeAudit> <before>  <table name="table1" description="Test Desc">   <product id="OldVal">  </table> </before> <after>  <table name="table1" description="Test Desc">   <product id="NewVal">  </table> </after></ProductMergeAudit>

View 2 Replies View Related

Compare Date Field To Text Field

Mar 27, 2008

Hi,

I am very new to using SQL. Our department usually uses Brio to query the various databases under our control. However, I have recently come against a problem that prompted me to create a custom SQL query which works well as far as it goes. My problem is looking for specific conditions in billing information I receive monthly. I would like to compare on of the date fields contained in the database with a field in the form of YYYYMM (200710, for October 2007) I have created a custom column generator that forms a date from the YYYYMM. I would like, however, do the translation on the fly and make the comparison during the query. The problem is that query without the date check returns a mass of data, only about 1 percent of which is what I want.

The beginning of the SQL query looks like this:

FROM From.T_Crs_Tran_Dtl WHERE T_Crs_Tran_Dtl.Crs_Bill_Yr_Mo IN ('200710', '200711', '200712') AND ((T_Crs_Tran_Dtl.Crs_Cde IN ('1G', '1V') AND (T_Crs_Tran_Dtl.Dptr_Dte < LastDay(ToDate(Substr ( Crs_Bill_Yr_Mo, 5, 2 )& "/1/"&Substr ( Crs_Bill_Yr_Mo, 1, 4 )))) AND (T_Crs_Tran_Dtl.Prev_Stats_Cde IN (' ', 'TK', 'TL') AND T_Crs_Tran_Dtl.Cur_Stats_Cde IN ('TK', 'TL') AND T_Crs_Tran_Dtl.Std_Tran_Typ_Cde='B') OR (T_Crs_Tran_Dtl.Prev_Stats_Cde='UN' AND T_Crs_Tran_Dtl.Cur_Stats_Cde='XX' AND€¦

It is the €œ(T_Crs_Tran_Dtl.Dptr_Dte < LastDay(ToDate(Substr ( Crs_Bill_Yr_Mo, 5, 2 )& "/1/"&Substr ( Crs_Bill_Yr_Mo, 1, 4 )))) AND€? part of the query that is just plain wrong. The business part of this statement takes the YYYYMM field and turns it into a date which is the last day of YYYYMM.

I hope someone out there can help me with making this comparison.

I appreciate your help.

Bill

View 8 Replies View Related

(Urgent) How Get A Text Field And Put The Result Into A Text Var

May 3, 2004

Hi All

Iam trying to Get a text field value i wrote this code

DECLARE @ptrval varbinary(16)
DECLARE @length bigint
SELECT @ptrval = TEXTPTR(Template), @length = LEN(Template)
FROM #TEMPLATE
READTEXT Template.#TEMPLATE @ptrval 0 @length

but i need to put the result into a text var
is that possible or not and if it possible any one could help me with that

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved