Solved

How to search the greatest count among four temporary table.

Posted on 2011-02-16
2
266 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

18 Experts available now in Live!

Get 1:1 Help Now