Solved

keywords count

Posted on 2014-01-29
6
377 Views
Last Modified: 2014-01-29
Dear all,
I have this table @KeyWords ( word, Count)
how to add all rows in @KeyWords  to another Table @AnotherKeyWords (word, Count)
if the word not exist in @AnotherKeyWords.


but if the word exist in @AnotherKeyWords   then @AnotherKeyWords .Count=@AnotherKeyWords .Count+@KeyWords.Count


thanks,
0
Comment
Question by:ethar1
  • 4
6 Comments
 
LVL 7

Assisted Solution

by:aplusexpert
aplusexpert earned 50 total points
ID: 39817388
Execute the following two queries:

Query1: add all rows in @KeyWords  to another Table @AnotherKeyWords (word, Count)
if the word not exist in @AnotherKeyWords:

INSERT INTO @AnotherKeyWords
FROM SELECT @KeyWords.Word, @KeyWords.COUNT FROM @KeyWords WHERE @KeyWords.Word NOT IN (SELECT @AnotherKeyWords.Word FROM @AnotherKeyWords)

Query2: if word exist in @AnotherKeyWords then @AnotherKeyWords .Count=@AnotherKeyWords .Count+@KeyWords.Count

UPDATE AKW SET AKW.COUNT = AKW.Count + @KeyWords.COUNT
FROM @AnotherKeyWords AKW INNER JOIN @KeyWORDS ON AKW.Word = @KeyWords.Word

(The inner join will ensure that only when Word is there in both tables, then COUNT will be updated).
0
 
LVL 12

Accepted Solution

by:
Harish Varghese earned 450 total points
ID: 39817397
Hello,
First do an update of the count in @AnotherKeyWords table for the matching words
And then insert the additional words from @KeyWords table along with count to @AnotherKeyWords.

Update AK
SET AK.Count = AK.Count + K.Count
From @AnotherKeyWords AK, @KeyWords K
Where AK.Word = K.Word

Insert into @AnotherKeyWords (Word, Count)
Select Word, Count
From @KeyWords K
Where Not Exists (Select 1 from @AnotherKeyWords AK Where AK.Word = K.Word)

-Harish
0
 

Author Closing Comment

by:ethar1
ID: 39817414
excellent
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:ethar1
ID: 39817751
0
 

Author Comment

by:ethar1
ID: 39818223
0
 

Author Comment

by:ethar1
ID: 39818493
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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
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.

912 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

19 Experts available now in Live!

Get 1:1 Help Now