Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Join making conflict....


Join making conflict....

Author
Message
Sgar...
Sgar...
SSC-Enthusiastic
SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)

Group: General Forum Members
Points: 179 Visits: 666
SELECT @MSGOUT = @MSGOUT + '
<tr>
<td>' + ss.ServerName +'</td>
<td>' + ss.DBName +'</td>
<td>' + Occurrences +'</td>

</tr>
'

FROM DBINVENTORY ss
INNER JOIN
   (SELECT ServerName,DBname,
cast(COUNT(dbname) as varchar(5))AS Occurrences
   FROM DBINVENTORY d
   GROUP BY ServerName,DBName
   HAVING ( COUNT(DBName) > 1 )
      Winksq ON ss.DBName=sq.DBName

this giving me output like

----------------------------------------

Server_Name   Dbname   Occurences
X   ABC   2
X   ABC   2
Y   HIJ   2
Y   HIJ   2
Y   NOP   2
Y   NOP   2
Z   BCD   4
Z   BCD   4
Z   BCD   4
Z   BCD   4
Z   JIK   4
Z   JIK   4
Z   JIK   4
Z   JIK   4
Z   JIK2   4
Z   JIK2   4
Z   JIK2   4
Z   JIK2   4
A   ABC   2
A   ABC   2
A   TUV   2
A   TUV   2
B   EFG   2
B   EFG   2
D   ACD   2
D   ACD   2
---------------------------------------

Actual output required is


Server_Name   Dbname   Occurences
X   ABC   2
Y   HIJ   2
Y   NOP   2
Z   BCD   4
Z   BCD   4
Z   JIK   4
Z   JIK   4
Z   JIK2   4
Z   JIK2   4
A   ABC   2
A   TUV   2
B   EFG   2
D   ACD   2


Please advise the join condition.....

Sagar Sonawane
** Every DBA has his day!!Cool
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16380 Visits: 13199
Maybe you can give some sample data for table DBINVENTORY.
Why is it OK for some servername-dbname pairs to have 2 rows as output and for others isn't?



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Sgar...
Sgar...
SSC-Enthusiastic
SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)

Group: General Forum Members
Points: 179 Visits: 666
Main objective is to find duplicate db's...... and out put is perfect..... which I am looking for....

Can you please help wi

Sagar Sonawane
** Every DBA has his day!!Cool
rhythmk
rhythmk
Say Hey Kid
Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)

Group: General Forum Members
Points: 662 Visits: 1062
Saga... (8/27/2012)


Main objective is to find duplicate db's...... and out put is perfect..... which I am looking for....

Can you please help wi


Sorry but it is difficult without the sample data and the actual requirement.Here none of these are not clear Sad

--rhythmk
------------------------------------------------------------------
To post your question use below link

http://www.sqlservercentral.com/articles/Best+Practices/61537/
:-)
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16380 Visits: 13199
Saga... (8/27/2012)


Main objective is to find duplicate db's...... and out put is perfect..... which I am looking for....

Can you please help wi


I asked two questions. You didn't answer any of them.
How much effort do you think I will put in your questions?



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Sgar...
Sgar...
SSC-Enthusiastic
SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)

Group: General Forum Members
Points: 179 Visits: 666
SELECT @MSGOUT = @MSGOUT + '
<tr>
<td>' + ss.ServerName +'</td>
<td>' + ss.DBName +'</td>
<td>' + Occurrences +'</td>

</tr>
'

FROM /*DBINVENTORY ss --after removing this commented words...I got required output
INNER JOIN*/

(SELECT ServerName,DBname,
cast(COUNT(dbname) as varchar(5))AS Occurrences
FROM DBINVENTORY d
GROUP BY ServerName,DBName
HAVING ( COUNT(DBName) > 1 )
)sq ON ss.DBName=sq.DBName

Sagar Sonawane
** Every DBA has his day!!Cool
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16539 Visits: 16992
Saga... (8/27/2012)
SELECT @MSGOUT = @MSGOUT + '
<tr>
<td>' + ss.ServerName +'</td>
<td>' + ss.DBName +'</td>
<td>' + Occurrences +'</td>

</tr>
'

FROM /*DBINVENTORY ss --after removing this commented words...I got required output
INNER JOIN*/

(SELECT ServerName,DBname,
cast(COUNT(dbname) as varchar(5))AS Occurrences
FROM DBINVENTORY d
GROUP BY ServerName,DBName
HAVING ( COUNT(DBName) > 1 )
)sq ON ss.DBName=sq.DBName


So does this mean you solved your issue or not?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8484 Visits: 18082
You were joining your grouped results with the original table with duplicates. You can get an even simpler version of your code like this, no need of a subquery:


SELECT @MSGOUT = @MSGOUT + '
<tr>
<td>' + ServerName +'</td>
<td>' + DBName +'</td>
<td>' + cast(COUNT(dbname) as varchar(5)) +'</td>

</tr>
'
FROM DBINVENTORY
GROUP BY ServerName,DBName
HAVING ( COUNT(DBName) > 1 )




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Sgar...
Sgar...
SSC-Enthusiastic
SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)

Group: General Forum Members
Points: 179 Visits: 666
Luis Cazares (8/27/2012)
You were joining your grouped results with the original table with duplicates. You can get an even simpler version of your code like this, no need of a subquery:


SELECT @MSGOUT = @MSGOUT + '
<tr>
<td>' + ServerName +'</td>
<td>' + DBName +'</td>
<td>' + cast(COUNT(dbname) as varchar(5)) +'</td>

</tr>
'
FROM DBINVENTORY
GROUP BY ServerName,DBName
HAVING ( COUNT(DBName) > 1 )




Thanks luis....

Sagar Sonawane
** Every DBA has his day!!Cool
Sgar...
Sgar...
SSC-Enthusiastic
SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)

Group: General Forum Members
Points: 179 Visits: 666
Sean Lange (8/27/2012)
Saga... (8/27/2012)
SELECT @MSGOUT = @MSGOUT + '
<tr>
<td>' + ss.ServerName +'</td>
<td>' + ss.DBName +'</td>
<td>' + Occurrences +'</td>

</tr>
'

FROM /*DBINVENTORY ss --after removing this commented words...I got required output
INNER JOIN*/

(SELECT ServerName,DBname,
cast(COUNT(dbname) as varchar(5))AS Occurrences
FROM DBINVENTORY d
GROUP BY ServerName,DBName
HAVING ( COUNT(DBName) > 1 )
)sq ON ss.DBName=sq.DBName


So does this mean you solved your issue or not?


Yes Sean...it solved my issue...

Sagar Sonawane
** Every DBA has his day!!Cool
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search