Solved

Check if @input  has any value listed in keyword table

Posted on 2014-01-29
13
262 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now