?
Solved

Check if @input  has any value listed in keyword table

Posted on 2014-01-29
13
Medium Priority
?
301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

771 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