Solved

Check if @input  has any value listed in keyword table

Posted on 2014-01-29
13
279 Views
Last Modified: 2014-02-03
Dear all,
I need to modify the answer of this question :
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_28344773.html

to check if @input  has any word list in keyword Table ( select TagTitle from NewsSYSTags where isComposedTagKeyword=1 )
then add it to @Keyword Table , also remove all founded keywords from @input  to prevent it from split function.

thanks
0
Comment
Question by:ethar1
  • 7
  • 6
13 Comments
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39821079
check if @input  has any word list in keyword Table ( select TagTitle from NewsSYSTags where isComposedTagKeyword=1 )
then add it to @Keyword Table


declare @KeyWords table
(
    word    VARCHAR(1000)
    ,Count  BIGINT
)

declare @input  nVARCHAR(max)
SET @input = 'A quick brown fox jumped over the hedge of your computer in a bussiness rather quick fashion'

select * FROM dbo.split(@input,' ')

;WITH C AS
(
    SELECT COUNT(1) CC,Data FROM dbo.split(@input,' ')
    GROUP BY DATA
)
UPDATE  K
SET     [count] = [count] + CC
FROM    @KeyWords K
JOIN    C
ON      K.word = C.data

;WITH C AS
(
    SELECT COUNT(1) CC,Data FROM dbo.split(@input,' ')
    GROUP BY DATA
)
INSERT INTO @KeyWords
SELECT DATA,CC FROM C
WHERE NOT EXISTS ( SELECT 1 FROM @KeyWords K WHERE K.word = C.data)
AND EXISTS ( SELECT 1 FROM NewsSYSTags S where isComposedTagKeyword=1 and S.TagTitle  = C.data)

SELECT * FROM @KeyWords 

Open in new window


also remove all founded keywords from @input  to prevent it from split function.

This will become a cumbersome process and will hit the performance than improving the performance...
0
 

Author Comment

by:ethar1
ID: 39823247
Dear Surendra Ganti, I don't understand your response.
let's divided to 2 parts
first I need to
 insert all key-words in @input founded in keyword here  ( select TagTitle from NewsSYSTags where isComposedTagKeyword=1 )
0
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39823349
thats correct that is exactly how above script works.

and regarding the second requirement of yours, I cannot give you a simple solution without knowing the volumes.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:ethar1
ID: 39823620
insert all key-words in @input founded in  ( select TagTitle from NewsSYSTags where isComposedTagKeyword=1 )  to @keyword

should be done before split
0
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39823666
are you looking for something like below???

declare @KeyWords table
(
    word    VARCHAR(1000)
    ,Count  BIGINT
)

INSERT INTO @KeyWords 
(
word,Count
)
select TagTitle,0 from NewsSYSTags where isComposedTagKeyword=1

declare @input  nVARCHAR(max)
SET @input = 'A quick brown fox jumped over the hedge of your computer in a bussiness rather quick fashion'

select * FROM dbo.split(@input,' ')

;WITH C AS
(
    SELECT COUNT(1) CC,Data FROM dbo.split(@input,' ')
    GROUP BY DATA
)
UPDATE  K
SET     [count] = [count] + CC
FROM    @KeyWords K
JOIN    C
ON      K.word = C.data

;WITH C AS
(
    SELECT COUNT(1) CC,Data FROM dbo.split(@input,' ')
    GROUP BY DATA
)
INSERT INTO @KeyWords
SELECT DATA,CC FROM C
WHERE NOT EXISTS ( SELECT 1 FROM @KeyWords K WHERE K.word = C.data)
AND EXISTS ( SELECT 1 FROM NewsSYSTags S where isComposedTagKeyword=1 and S.TagTitle  = C.data)

SELECT * FROM @KeyWords 

Open in new window

0
 

Author Comment

by:ethar1
ID: 39823681
we have 2 type of keywords ,
first type defined from a keywords master table

second type generated from split statement


****
for first type we need to search any keyword in @input  listed in master table of keywords
0
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39823707
Ok, rather than we go back and forth

Why dont you take an example, this might help us understand the stuff better.
0
 

Author Comment

by:ethar1
ID: 39823812
very simple
I have @input , need to find any word in @input  listed in simple table ( kID, Keyword) and add the founded in another table
0
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39823888
Then why are insisting to do it before spliting the @input into a table, it can also be done after the split?

is there any bussiness reason for that?
0
 

Author Comment

by:ethar1
ID: 39823905
caz the keywords may contains 2 or more words
0
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39823951
check this out

declare @KeyWords table
(
    word    VARCHAR(1000)
    ,Count  BIGINT
)

declare @input  nVARCHAR(max)
SET @input = 'A quick brown fox jumped over the hedge of your computer in a bussiness rather quick fashion'

INSERT INTO @KeyWords 
(
word,count
)
select TagTitle,0 from NewsSYSTags 
where isComposedTagKeyword=1
and @input LIKE '%' + TagTitle + '%'

select * FROM dbo.split(@input,' ')

;WITH C AS
(
    SELECT COUNT(1) CC,Data FROM dbo.split(@input,' ')
    GROUP BY DATA
)
UPDATE  K
SET     [count] = [count] + CC
FROM    @KeyWords K
JOIN    C
ON      K.word = C.data

;WITH C AS
(
    SELECT COUNT(1) CC,Data FROM dbo.split(@input,' ')
    GROUP BY DATA
)
INSERT INTO @KeyWords
SELECT DATA,CC FROM C
WHERE NOT EXISTS ( SELECT 1 FROM @KeyWords K WHERE K.word = C.data)

SELECT * FROM @KeyWords 
                                            

Open in new window

0
 

Author Closing Comment

by:ethar1
ID: 39824165
Thanks
0
 

Author Comment

by:ethar1
ID: 39831032
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TSQL query to generate xml 4 36
SSRS Enable Remote Errors 4 27
Loops and updating in SQL Query 9 33
SQL Count issue 24 18
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question