Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Declare statement question

Author  Topic 

Sql newbie1
Starting Member

8 Posts

Posted - 2011-02-26 : 12:19:14
Hi guys

I have compiled a query usng declare as there are quite a few tables involved usng the same primary key. What I want to know is if there is a way to just display the tables that have results in them rather than what happens now which is that it shows all the tables in the results window with the ones that have no entries being blank? Any help would be appreciated.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-02-26 : 12:48:35
you can use if condition achieve this. just check for condition count(*) > 0 from tables before displaying them

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sql newbie1
Starting Member

8 Posts

Posted - 2011-02-26 : 15:16:03
Thanks for the reply, would you possibly be able to give me an example script?
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-02-26 : 15:21:48
"A problem well stated is a problem half solved." -- Charles F. Kettering

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. If you know how, follow ISO-11179 data element naming conventions and formatting rules. Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.

Sample data is also a good idea, along with clear specifications. It is very hard to debug code when you do not let us see it. If you want to learn how to ask a question on a Newsgroup, look at: http://www.catb.org/~esr/faqs/smart-questions.html



--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page

Sql newbie1
Starting Member

8 Posts

Posted - 2011-02-26 : 18:29:34
thnx for the reply. All I want is to not display any tables in the results that have no entries instead of showing them with no results
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-03 : 09:41:55
if exists(select * from table)
select .........

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Sql newbie1
Starting Member

8 Posts

Posted - 2011-03-03 : 17:15:55
Brilliant, thanks for the reply
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-03 : 17:52:38
When you say results? DO you mean Data in them>>


JOEY!! Where have you Bean

DECLARE myCursor99 CURSOR.....





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Sql newbie1
Starting Member

8 Posts

Posted - 2011-03-04 : 03:21:52
Sorry yes only display tables with result (data)s in them rather than all tables inc ones with no results
Go to Top of Page
   

- Advertisement -