Solved

How to search the greatest count among four temporary table.

Posted on 2011-02-16
2
311 Views
Last Modified: 2012-05-11
I have four temporary tables, they are billingaddress, postaladdress, shippingaddress, officeaddress now there are different number of rows in each table. I want to find out which of them has highest number of rows and assign the variable @x that value. how to get the highest count(*) among 4 #temporary tables?
0
Comment
Question by:ExpertKapur
[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
2 Comments
 
LVL 8

Accepted Solution

by:
rushShah earned 125 total points
ID: 34909091
you can try something like this,


DECLARE @x INT
select @x = Count(*) from billingaddress
select @x = CASE WHEN @x > Count(*) then @x else Count(*) end from postaladdress
select @x = CASE WHEN @x > Count(*) then @x else Count(*) end from shippingaddress
select @x = CASE WHEN @x > Count(*) then @x else Count(*) end  from officeaddress

select @x

Open in new window

0
 
LVL 13

Assisted Solution

by:devlab2012
devlab2012 earned 125 total points
ID: 34909097

select max(cnt) from
(
select count(*) AS cnt from tb1
UNION ALL
select count(*) AS cnt from tb2
UNION ALL
select count(*) AS cnt from tb3
UNION ALL
select count(*) AS cnt from tb4
) #temp
0

Featured Post

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.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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