Solved

Check if @input  has any value listed in keyword table

Posted on 2014-01-29
13
293 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

695 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