Conducting A Radius Search Via Postcodes - Cursor Issue?

Feb 22, 2004

Hi, I’ve developed the following stored procedure to query a table of services following a user search. The user can specify a radius from a certain location(UK postcode) in which to search, and its with this Im having a few problems.





Here’s my method:





STEP1 - I first check the table of services and insert all services matching the specified criteria (regardless of location) into a temporary table (#tMatches).





STEP 2 - I get the postcode entered by the user and retrieve its co-ordinates.





STEP 3 – I open a cursor and loop through the records in #tMatches. For each record, I first retrieve their co-ordinates and then use a bit of Pythagoras to work out whether its location falls within the radius specified by the user.





STEP 4 – If the record falls outside the range specified by the user, I deleted from #tMatches.





STEP 5 – I bind the remaining (matching) records from the #tMatches to a dataset.





Now, I think that seems pretty simple, and the easiest way to achieve what I’m trying to do. How then when querying just 600 records am I finding it times out? I think I’ve pinned it down to the STEP 3 (cursor), but not being the SQL expert I’d like to be, I’ve no further ideas where I’m going wrong? Any ideas?





The following is an excerpt from the script - don't worry about the fact several parameters may not be declared.





Many thanks





======================================





--STEP 1


CREATE TABLE #tMatches


(


record_uid uniqueidentifier,


service_name varchar(500),


service_address varchar(500),


service_description varchar(500),


GRE integer,


GRN integer


)


BEGIN


INSERT INTO #tMatches


(record_uid,service_name,service_address,service_description,GRE,GRN)


SELECT service_loc_uid,title_return,service_address,service_overview,GRE,GRN FROM v_RecordsLive_short WHERE (title_return LIKE '%' + @lookingfor + '%' OR service_category LIKE '%' + @lookingfor + '%' OR service_overview LIKE '%' + @lookingfor + '%')


END





-STEP 2





DECLARE @UserCoordX integer


DECLARE @UserCoordY integer


--1) USE POSTCODE DATA FOR REGION ONLY


SELECT @UserCoordX = GRE,@UserCoordY = GRN FROM tPCD WHERE tPCD.PCD = @postcode





--STEP3





--open a cursor containing record ids with co-ordinates


DECLARE @record_uid uniqueidentifier


DECLARE @CoordX integer


DECLARE @CoordY integer


DECLARE @XLen integer


DECLARE @YLen integer


DECLARE @range real





DECLARE locs_cursor CURSOR FOR


SELECT record_uid,GRE,GRN FROM #tMatches





OPEN locs_cursor





FETCH NEXT FROM locs_cursor


INTO @record_uid,@CoordX,@CoordY





WHILE @@FETCH_STATUS = 0


BEGIN


--calculate range from entered postcode using pythagorus


SET @XLen = Abs(@UserCoordX - @CoordX)


SET @YLen = Abs(@UserCoordY - @CoordY)


SET @range = SQRT((@XLen * @XLen) + (@YLen * @YLen))





END





--convert range to miles


SET @range = COALESCE(@range,0)


IF (@range > 0)


SET @range = @range/160.9





--IF OUT OF RANGE, DELETE RECORD FROM TABLE STRAIGHTAWAY


IF @range > CAST(@miles as float)


DELETE FROM #tMatches WHERE record_uid = @record_uid





--get next record


FETCH NEXT FROM locs_cursor


INTO @record_uid,@CoordX,@CoordY





CLOSE locs_cursor


DEALLOCATE locs_cursor





--------------------RETURN ALL RESULTS-----------------------------------------------


SELECT record_uid,service_name,service_address,service_description FROM #tMatches





DROP Table #tMatches

View 3 Replies


ADVERTISEMENT

Radius Search

Oct 10, 2006


I have latitude and longitude in my database, can anyone give me an sql query how I can make radius search based on that?

View 3 Replies View Related

Zip Code Radius With Inner Join

Aug 29, 2007

Hey, i need some help with my query structure.. I have my zip code database, and then a listings table, with a zip code in one of the columns.  I want to return all that data from both frields where the zip code radius results are.  here's my stored procedure:*removed*Any ideas?

View 1 Replies View Related

Postcode Radius Searching

Jul 20, 2005

Hi - I know this isn't really a specific SQL Server question but Ican't think of a better forum.I want to implement a more sophisticated UK postcode search on a site- "LIKE 'NW%'" etc, is not bringing back good enough results.A feature that would allow me to ask: "give me all outward postcodesin a 30 mile radius of NW10" would be ideal.Has anyone had to do this before? - any advice on how muchappreciated. Some of the postcode products available don't reallyseem to offer this feature.NH

View 2 Replies View Related

Store Procedure To Find City And Zip Code By Radius

Mar 20, 2007

Hi,
 
Is anyone has store procedure that find city and zipcode by radius (10 miles, 30 miles, 50 miles.......)
and also table that has all zipcodes. I finded one, but it's look like very old one, not updated since 2005
 
Thanks
Kate
 
 

View 1 Replies View Related

T-SQL (SS2K8) :: Calculation - Get Records Based On 100 / 80 / 60 / 40 Miles Radius

Feb 9, 2015

I have zip code database and i am trying to get the records based on 100/80/60/40 miles radius. Below the sample structure of my table

Create table ZipCodes(ID bigint primary key identity(1,1),ZipCode varchar(10),
Address varchar(4000), city varchar(50),state varchar(50),Latitude float,Longitude float)If i pass the Zipcode as '10021'

I need to get zipcodes and other details of my table which is 20 mile radius circle.

I Google through and got couple of article explains about using Haversine Formula. Also, following link has a function to calculate the distance.

View 9 Replies View Related

SQL 2000 MS Search: Boolean Search Doesn't Work When Search By Phrase

Aug 9, 2006

I'm just wonder if this is a bug in MS Search or am I doing something wrong.

I have a query below

declare @search_clause varchar(255)

set @Search_Clause = ' "hepatitis b" and "hepatocellular carcinoma"'

select * from results

where contains(finding,@search_clause)

I don't get the correct result at all.

If I change my search_clause to "hepatitis" and "hepatocellular carcinoma -- without the "b"

then i get the correct result.

It seems MS Search doesn't like the phrase contain one letter or some sort or is it a know bug?

Anyone know?

Thanks

View 3 Replies View Related

Transact SQL :: STATIC Defines A Cursor That Makes Temporary Copy Of Data To Be Used By Cursor

Aug 12, 2015

In MSDN file I read about static cursor

STATIC
Defines a cursor that makes a temporary copy of the data to be used by the cursor. All requests to the cursor are answered from this temporary table in
tempdb; therefore, modifications made to base tables are not reflected in the data returned by fetches made to this cursor, and this cursor does not allow modifications

It say's that modifications is not allowed in the static cursor. I have a  questions regarding that

Static Cursor
declare ll cursor global static
            for select  name, salary from ag
  open ll
             fetch from ll
 
              while @@FETCH_STATUS=0
               fetch from ll
                update ag set salary=200 where 1=1
 
   close ll
deallocate ll

In "AG" table, "SALARY" was 100 for all the entries. When I run the Cursor, it showed the salary value as "100" correctly.After the cursor was closed, I run the query select * from AG.But the result had updated to salary 200 as given in the cursor. file says  modifications is not allowed in the static cursor.But I am able to update the data using static cursor.

View 3 Replies View Related

Dynamic Cursor Versus Forward Only Cursor Gives Poor Performance

Jul 20, 2005

Hello,I have a test database with table A containing 10,000 rows and a tableB containing 100,000 rows. Rows in B are "children" of rows in A -each row in A has 10 related rows in B (ie. B has a foreign key to A).Using ODBC I am executing the following loop 10,000 times, expressedbelow in pseudo-code:"select * from A order by a_pk option (fast 1)""fetch from A result set""select * from B where where fk_to_a = 'xxx' order by b_pk option(fast 1)""fetch from B result set" repeated 10 timesIn the above psueod-code 'xxx' is the primary key of the current Arow. NOTE: it is not a mistake that we are repeatedly doing the Aquery and retrieving only the first row.When the queries use fast-forward-only cursors this takes about 2.5minutes. When the queries use dynamic cursors this takes about 1 hour.Does anyone know why the dynamic cursor is killing performance?Because of the SQL Server ODBC driver it is not possible to havenested/multiple fast-forward-only cursors, hence I need to exploreother alternatives.I can only assume that a different query plan is getting constructedfor the dynamic cursor case versus the fast forward only cursor, but Ihave no way of finding out what that query plan is.All help appreciated.Kevin

View 1 Replies View Related

Could Not Complete Cursor Operation Because The Set Options Have Changed Since The Cursor Was Declared.

Sep 20, 2007

I'm trying to implement a sp_MSforeachsp howvever when I call sp_MSforeach_worker
I get the following error can you please explain this problem to me so I can over come the issue.


Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 31

Could not complete cursor operation because the set options have changed since the cursor was declared.

Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 32

Could not complete cursor operation because the set options have changed since the cursor was declared.

Msg 16917, Level 16, State 1, Procedure sp_MSforeach_worker, Line 153

Cursor is not open.

here is the stored procedure:


Alter PROCEDURE [dbo].[sp_MSforeachsp]

@command1 nvarchar(2000)

, @replacechar nchar(1) = N'?'

, @command2 nvarchar(2000) = null

, @command3 nvarchar(2000) = null

, @whereand nvarchar(2000) = null

, @precommand nvarchar(2000) = null

, @postcommand nvarchar(2000) = null

AS

/* This procedure belongs in the "master" database so it is acessible to all databases */

/* This proc returns one or more rows for each stored procedure */

/* @precommand and @postcommand may be used to force a single result set via a temp table. */

declare @retval int

if (@precommand is not null) EXECUTE(@precommand)

/* Create the select */

EXECUTE(N'declare hCForEachTable cursor global for

SELECT QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_TYPE = ''PROCEDURE''

AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)), ''IsMSShipped'') = 0 '

+ @whereand)

select @retval = @@error

if (@retval = 0)

EXECUTE @retval = [dbo].sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 0

if (@retval = 0 and @postcommand is not null)

EXECUTE(@postcommand)

RETURN @retval



GO


example useage:


EXEC sp_MSforeachsp @command1="PRINT '?' GRANT EXECUTE ON ? TO [superuser]"

GO

View 7 Replies View Related

Join Cursor With Table Outside Of Cursor

Sep 25, 2007

part 1

Declare @SQLCMD varchar(5000)
DECLARE @DBNAME VARCHAR (5000)

DECLARE DBCur CURSOR FOR
SELECT U_OB_DB FROM [@OB_TB04_COMPDATA]

OPEN DBCur
FETCH NEXT FROM DBCur INTO @DBNAME


WHILE @@FETCH_STATUS = 0
BEGIN

SELECT @SQLCMD = 'SELECT T0.CARDCODE, T0.U_OB_TID AS TRANSID, T0.DOCNUM AS INV_NO, ' +
+ 'T0.DOCDATE AS INV_DATE, T0.DOCTOTAL AS INV_AMT, T0.U_OB_DONO AS DONO ' +
+ 'FROM ' + @DBNAME + '.dbo.OINV T0 WHERE T0.U_OB_TID IS NOT NULL'
EXEC(@SQLCMD)
PRINT @SQLCMD
FETCH NEXT FROM DBCur INTO @DBNAME

END

CLOSE DBCur
DEALLOCATE DBCur


Part 2

SELECT
T4.U_OB_PCOMP AS PARENTCOMP, T0.CARDCODE, T0.CARDNAME, ISNULL(T0.U_OB_TID,'') AS TRANSID, T0.DOCNUM AS SONO, T0.DOCDATE AS SODATE,
SUM(T1.QUANTITY) AS SOQTY, T0.DOCTOTAL - T0.TOTALEXPNS AS SO_AMT, T3.DOCNUM AS DONO, T3.DOCDATE AS DO_DATE,
SUM(T2.QUANTITY) AS DOQTY, T3.DOCTOTAL - T3.TOTALEXPNS AS DO_AMT
INTO #MAIN
FROM
ORDR T0
JOIN RDR1 T1 ON T0.DOCENTRY = T1.DOCENTRY
LEFT JOIN DLN1 T2 ON T1.DOCENTRY = T2.BASEENTRY AND T1.LINENUM = T2.BASELINE AND T2.BASETYPE = T0.OBJTYPE
LEFT JOIN ODLN T3 ON T2.DOCENTRY = T3.DOCENTRY
LEFT JOIN OCRD T4 ON T0.CARDCODE = T4.CARDCODE
WHERE ISNULL(T0.U_OB_TID,0) <> 0
GROUP BY T4.U_OB_PCOMP, T0.CARDCODE,T0.CARDNAME, T0.U_OB_TID, T0.DOCNUM, T0.DOCDATE, T3.DOCNUM, T3.DOCDATE, T0.DOCTOTAL, T3.DOCTOTAL, T3.TOTALEXPNS, T0.TOTALEXPNS


my question is,
how to join the part 1 n part 2?
is there posibility?

View 1 Replies View Related

Help W/ Stored Procedure? - Full-text Search: Search Query Of Normalized Data

Mar 29, 2008

 Hi -  I'm short of SQL experience and hacking my way through creating a simple search feature for a personal project. I would be very grateful if anyone could help me out with writing a stored procedure. Problem: I have two tables with three columns indexed for full-text search. So far I have been able to successfully execute the following query returning matching row ids:  dbo.Search_Articles        @searchText varchar(150)        AS    SELECT ArticleID     FROM articles    WHERE CONTAINS(Description, @searchText) OR CONTAINS(Title, @searchText)    UNION    SELECT ArticleID     FROM article_pages    WHERE CONTAINS(Text, @searchText);        RETURN This returns the ArticleID for any articles or article_pages records where there is a text match. I ultimately need the stored procedure to return all columns from the articles table for matches and not just the StoryID. Seems like maybe I should try using some kind of JOIN on the result of the UNION above and the articles table? But I have so far been unable to figure out how to do this as I can't seem to declare a name for the result table of the UNION above. Perhaps there is another more eloquent solution? Thanks! Peter 

View 3 Replies View Related

SQL Search :: Full Text Search With Single Character Returns All Rows

Jul 21, 2015

Our clients want to be able to do full text search with a single letter. (Is the name Newton, Nathan, Nick?, Is the ID N1, N2...). Doing a single character full text search on a table work 25 out of 26 times. The letter that doesn't work is 'n'. the WHERE clause CONTAINS(full_text_field, ' "n*" ') returns all rows, even rows that have no 'n' in them anywhere. Adding a second letter after the "n" works as expected.

Here is an example

create table TestFullTextSearch (
Id int not null,
AllText nvarchar(400)
)
create unique index test_tfts on TestFullTextSearch(Id);
create fulltext catalog ftcat_tfts;

[Code] ....

View 4 Replies View Related

SQL Server 2014 :: Semantic Search Not Finding Keywords Identified By Full-Text Search?

Nov 6, 2014

I have a scenario of where the standard Full-Text search identifies keywords but Semantic Search does not recognize them as keywords. I'm hoping to understand why Semantic Search might not recognize them. The context this is being used in medical terminology and the specific key words I noticed missing right off the bat were medications.

For instance, if I put the following string into a FT indexed table

'J9355 - Trastuzumab (Herceptin)'
AND
'J9355 - Trastuzumab emtansine'

The Semantic Search recognized 'Herceptin' and 'Emtansine' but not 'Trastuzumab'

Nor in

'J8999 - Everolimus (Afinitor)'

It did not recognize 'Afinitor' as a keyword.

In all cases the Base of Full-Text did find those keywords and were identifiable using the dmvsys.dm_fts_index_keywords_by_document.It does show the index as having completed.

why certain words might not be picked up while others would be? Could it be a language/dictionary issue? I am using English and accent insensitive settings?

View 0 Replies View Related

Create Site Search Using Sql Server Full Text Search

Jul 24, 2007

would you use sql server "full text search" feature as your site index?  from some reason i can't make index server my site search catalog, and i wonder if the full text is the solution. i think that i wll have to you create new table called some thing like "site text" and i will need to write every text twice- one the the table (let's say "articles table") and one to the text. other wise- there is problems finding the right urlof the text, searching different tables with different columns name and so on...
so i thought create site search table, with the columns:
id, text, url
and to write every thing to this table.
but some how ot look the wrong way, that every forum post, every article, album picture or joke will insert twice to the sqr server...
what do you think? 

View 1 Replies View Related

SQL Search :: Full Text Search Of PDF Files In A File Table

Mar 30, 2013

I have installed the Adobe iFilter 11 64 bit and set the path to the bin folder. I still cannot find any text from the pdf files. I suspect I am missing something trivial because I don't find much when I Bing for this so it must not be a common problem.Here is the code.

--Adobe iFilter 11 64 bit is installed
--The Path variable is set to the bin folder for the Adobe iFilter.
--SQL Developer version 64 bit on both Windows 7 and Windows 8.
USE master;
GO
DROP DATABASE FileTableStudy;
GO
CREATE DATABASE FileTableStudy
ON PRIMARY

[code]....

View 14 Replies View Related

How Can I Search Throught DOCX (MS Word 2007) Documents By SQL Server 2005 Full Text Search Engine?

Dec 11, 2006

How can I search throught DOCX (MS Word 2007) documents by SQL Server 2005 Full Text Search engine?

Should I something download?

View 6 Replies View Related

Full-Text Search: Prefix / Suffix Search

Sep 14, 2004

Please help me to create an SQL Server 2000 Stored Procedure for using prefix and suffix terms.

Example:

Say I want to find "Terminator" (1984).

I want to be able to use "Term" or "ator" as search results and still return the proper record.

Here is my Stored Procedure creation sql:


CREATE PROCEDURE sps_searchTitles(@searchTerm varchar(255)) AS
SELECT * FROM Video
WHERE FREETEXT (Video.*, '"*@searchTerm*"')
GO


--- The above does not appear to properly check both prefix ("Term---") and suffix ("---ator") terms.

I am trying to accomplish what is similarly done with LIKE '%term%'.

thanks, YM

View 1 Replies View Related

SQL 2012 :: FullText Search - Can Search Terms Come From Another Table

Mar 25, 2015

I have a table that contains words that will be used to search another table where FullText index has been created on searchable columns. I'm basically trying to run something like this:

SELECT t1.col1, t2.col3
FROM tbl1 t1, tbl2 t2
WHERE CONTAINS (t1.col1, t2.col1)

I know this won't work but is there a way to join these two tables so the words (t2.col1) can be passed as search conditions? There is no common key on both tables so normal join won't work. I'm trying to find a way to pass the search words from one table to another.

View 0 Replies View Related

Full Text Search- Substring Search Not Working

Jul 6, 2007

I have Sql server 2005 SP2.
I enabled it for Full Text search. Substring search where i enter *word* doesn't return any row.
I have a table testtable where description has word Extinguisher.

If i run a query with *ting* it doesn't return any row.
select * from testtable where contains(description,'"*xting*"') ;

But it works if i do
select * from testtable where contains(description,'"Exting*"') ;

The Full text search document says it supports substring search.
Is it an issue with sql server 2005?Please help.

View 7 Replies View Related

SQL Search :: Can't Get Expected Results With Contains And Full Text Search?

Nov 1, 2015

I am using Sql Server 2014 Express edition.I have a table with a varchar(max) column. I have created a full text search that use the stoplist "system". column has this struct: xxx.yyy.zzz.... where xxx, yyy, zzz... are numbers, like 123.345.123123.366456...I can have rows like that:

123.345
123.345
123.345.444
123.345.555
123.345.666
123.345.444.777
123.345.444.888
123.345.555.999

I am trying this query:

select * from Mytable where
contains(MyColumn, '123.345.')

I gues the contains would return all the rows with column contains 123.345, but this does not return all the expected rows, only one row.I have tried to replace "." with "-" but the result is the same.I have also tried with '123.345.*. In this case I have got more results, but no all the exptected rows.If I use this query:

select * from MyTable where
MyCOlumn like '123.345.%';

View 12 Replies View Related

How To Search A Database For A Key Word Based Search?

Mar 1, 2007

Can anyone tell me how to search an SQL database for a given key word in a textbox? I basically have a database that has a qualifications column and this column needs to be searched for the data given in the textbox. Which is the best method to search for the data? Is it a simple SQL query or an XML based search engine type? Can anyone give any suggestions regarding this? If XML is efficient then how do I use it to query my database, as I'm pretty new in XML based searching.Thanks 

View 5 Replies View Related

How To Make A Search Engine To Search My Database

Nov 22, 2007

hi there,
 i am doing a school project and i need to have this search engine that will search the data that i have stored inside the database and display the results out
can anyone help?
thanks

View 6 Replies View Related

Why I Always See That Full Text Search Is Always Slower Than LIKE Search?

Apr 2, 2004

for example:

SELECT * from [table1] WHERE CONTAINS([msgcomment], '"fast" NEAR "performance"')

would always slower than

SELECT * from [table1] WHERE [msgcomment] = '%fast%performance%'


Why? and how can it be solved? can you help me?

:)

View 6 Replies View Related

Fulltext Search DB - Allow Users To Search Products

Dec 6, 2011

My site uses a text box to allow visitors to search products. I'm trying to design the SQL Statement to allow search's on full words, part words, and words/phrases regardless of the order the words are in.

E.g.
megger
meg
mft megger (proper order in the database is megger mft)
mft1710 (using 1710 should find the product)

This is my select statement (classic ASP)

Code:
<%
Dim RSResults__param5
RSResults__param5 = "xxx"
If (Request("searchme") <> "") Then
RSResults__param5 = Request("searchme")
End If

[Code] ....

View 1 Replies View Related

SQL Search :: Full Text Search Anomaly

Jun 24, 2015

I'm experiencing an anomaly with my Full text index.

Setup : SQL Server 2005
Indexed Table:
Assets
ID - int (PK, auto increment)
Ref - varchar(50)

[code]....

I have re-built the full-text index, no change.

View 2 Replies View Related

Cursor Inside A Cursor

Oct 5, 2004

I'm new to cursors, and I'm not sure what's wrong with this code, it run for ever and when I stop it I get cursor open errors




declare Q cursor for
select systudentid from satrans


declare @id int

open Q
fetch next from Q into @id
while @@fetch_status = 0
begin

declare c cursor for

Select
b.ssn,
SaTrans.SyStudentID,
satrans.date,
satrans.type,
SaTrans.SyCampusID,
Amount = Case SaTrans.Type
When 'P' Then SaTrans.Amount * -1
When 'C' Then SaTrans.Amount * -1
Else SaTrans.Amount END

From SaTrans , systudent b where satrans.systudentid = b.systudentid

and satrans.systudentid = @id




declare @arbalance money, @type varchar, @ssn varchar, @amount money, @systudentid int, @transdate datetime, @sycampusid int, @before money

set @arbalance = 0
open c
fetch next from c into @ssn, @systudentid, @transdate, @type, @sycampusid, @amount

while @@fetch_status = 0
begin

set @arbalance = @arbalance + @amount
set @before = @arbalance -@amount

insert c2000_utility1..tempbalhistory1
select @systudentid systudentid, @sycampusid sycampusid, @transdate transdate, @amount amount, @type type, @arbalance Arbalance, @before BeforeBalance
where( convert (int,@amount) <= -50
or @amount * -1 > @before * .02)
and @type = 'P'




fetch next from c into @ssn, @systudentid, @transdate, @type, @sycampusid, @amount
end
close c
deallocate c
fetch next from Q into @id

end
close Q
deallocate Q


select * from c2000_utility1..tempbalhistory1
truncate table c2000_utility1..tempbalhistory1

View 1 Replies View Related

Full Text Search Vs LIKE Search

Jan 24, 2006

Are there any big differences between the two search techniques? It seems like they are both very similar.

SELECT * FROM TABLE1 WHERE TEXTFIELD1 LIKE '%DATABASES%'
SELECT * FROM TABLE1 WHERE CONTAINS (TEXTFIELD1 ,' "DATABASES" ')

View 2 Replies View Related

Client Side Cursor Vs Sever Side Cursor?

Jul 20, 2005

I having a difficult time here trying to figure out what to do here.I need a way to scroll through a recordset and display the resultswith both forward and backward movement on a web page(PHP usingADO/COM)..I know that if I use a client side cursor all the records get shovedto the client everytime that stored procedure is executed..if thisdatabase grows big wont that be an issue?..I know that I can set up a server side cursor that will only send therecord I need to the front end but..Ive been reading around and a lot of people have been saying never touse a server side cursor because of peformance issues.So i guess im weighing network performance needs with the client sidecursor vs server performance with the server side cursor..I am reallyconfused..which one should I use?-Jim

View 1 Replies View Related

Search Within Search Results?

Mar 14, 2007

Hi guys
I need to create an "advanced search" which will allow the user to narrow down his results.
Ideally I'd want him/her to use the same search criteria form for each iteration, with a checkbox called "Search within results" type of thing.
Now what I was wondering if there was any existing literature on how to effectively do this. I have tried doing it just through SQL Statements but they are becoming very messy and large.
Is it possible to do this by searching the initial dataset, returning dataset #2 and then if a 3rd "search within results" is done apply the search against dataset #2 and return dataset #3 etc?
Many Thanks
John

View 2 Replies View Related

Tag Search And Tag Cloud Search

Apr 14, 2008

--set ANSI_NULLS ON
--set QUOTED_IDENTIFIER ON
--go
--
--
--ALTER PROC [dbo].[spEventTagCloud]
--as
--BEGIN
DECLARE @RECORDCOUNT INT;
DECLARE @SearchString varchar(2000);
DECLARE @QRY VARCHAR(2000);
DECLARE @SE VARCHAR(2000);
SELECT @RECORDCOUNT=COUNT(*) FROM TBEVENTS
DECLARE @ST INT;
SET @ST=1;
CREATE TABLE #TEMP2
(
MYTAGS VARCHAR(2000)
)
--CREATE TABLE #TEMP3
--(
-- TAGCOUNT INT
--)
CREATE TABLE #TEMP1
(
STR1 VARCHAR(2000)
)
WHILE @ST<@RECORDCOUNT
BEGIN
SET @QRY='SELECT TOP ' +CONVERT(VARCHAR,@ST)+' EVENTTAG FROM TBEVENTS'
--PRINT @QRY
INSERT INTO #TEMP1 EXEC (@QRY)
SELECT @SEARCHSTRING=STR1 FROM #TEMP1
SET @ST=@ST+1
declare @i1 int;
declare @i2 int;
declare @MatchType int ;
set @MatchType=0;
declare @Word varchar(100);
declare @Words table (Word varchar(100) not null);
declare @WordCount as integer;
DECLARE @TEMPWORD VARCHAR(2000);
begin
set nocount on
if (@MatchType != 2)
begin
set @SearchString = ' ' + @SearchString + ',';
--print 'Search String is :::: '+ @SearchString
set @i1 = 1;
while (@i1 != 0)
begin
set @i2=charindex(',', @SearchString, @i1+1)
--print @i1
if (@i2 != 0)
begin
set @Word = rtrim(ltrim(substring(@SearchString, @i1+1, @i2-@i1)))

SET @TEMPWORD=@WORD;
SET @TEMPWORD=REPLACE(@TEMPWORD,',','')
INSERT INTO #TEMP2 SELECT @TEMPWORD
--print 'Search WORD is :::: '+ @WORD

if @Word != '' insert into @Words select replace(@Word,',','')
end
set @i1 = @i2
end
end
else
insert into @Words select ltrim(rtrim(@SearchString))
set @WordCount = (select count(*) from @Words)
Declare @wordtemp varchar(2000);
set @wordtemp=@word
set @wordtemp=replace(@word,',','')
--INSERT INTO #TEMP2 SELECT @WORDtemp
END
END
SELECT mytags'Tag' , count(mytags)'Count' FROM #TEMP2 group by mytags ORDER BY [COUNT] DESC
--SELECT * FROM #TEMP1
DROP TABLE #TEMP1
DROP TABLE #TEMP2
--DROP TABLE #TEMP3
--END

________________________________
THE ABOVE EXAMPLE FOR A TAG CLOUD
MY TAGS ARE AS FOLLOW

EVENTTAG
_________
ASP.NET, C#, VB.NET
WELCOME TO ASP.NET
ASP.NET BOOKS,C#.NET BOOKS


I WOULD LIKE TO SELECT ALL COLUMNS FROM MY TABLE SEARCH TAG IS ASP.NET
THE FOLLOWING CODE WILL GENERATE AND SPLIT IT AS

TAG
____
ASP.NET
c#
VB.NET
WELCOME TO ASP.NET
ASP.NET BOOKS
C#.NET BOOKS

HOW TO SEARCH AN EXACT MATCH AS ASP.NET THE ONLY ONE ROW

View 3 Replies View Related

Need Help With A Cursor

Jul 25, 2006

I hope this is the appropriate forum for this question, if not then I apologize.
I've got a SQL Server 2000 stored procedure that returns data to be used in a crystal report in Visual Studio 2005.  Most of the stored procedure works well, but there is a point where I need to calculate an average number of days been a group of date pairs. 
I'm not familiar with cursors, but I think that I will need to use one to achieve the result I am looking for so I came up with the code below which is a snippet from my stored procedure.  In this part of the code, the sp looks at the temporary table #lmreport (which holds all of the data that is returned at the end to crystal) and for every row in the table where the terrid is 'T' (the territory is domestic), it selects all of those territories from the territory table and loops through them to determine the date averages (by calling a nested stored procedure, also included below) for each territory and then updates #lmreport with that data.
When I try to run the stored procedure, I get "The column prefix '#lmreport' does not match with a table name or alias name used in the query." on the line indicated. 
Does anyone have any idea what might be wrong or if this will even work the way I need it to?
Thank you in advance.
 

View 1 Replies View Related

Cursor For

Sep 27, 2007

Hi,
Declare wh_ctry_id CURSOR FOR 
 
Is "cursor for" is a function or datatype or what is this?
Regards
Abdul

View 3 Replies View Related







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