|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
||||
|
||||
|
If-statements and count
I'm not particularly adept in SQL :|
I want to perform some SQL under the condition that the count of a table is 0. Something like... Code:
IF ( (SELECT COUNT(*) FROM table1) = 0 ) Could someone help me with the syntax of this? Thanks in advance |
|
#3
|
||||
|
||||
|
It appears the if-block is ALWAYS being entered
Code:
IF ((SELECT COUNT(*) FROM table1) = 0) BEGIN -- some SQL here END If I run the SELECT statement, I get 178683 returned. The SQL inside the BEGIN and END still gets ran. Any ideas? Last edited by AndyMNE : April 29th, 2008 at 10:44 AM. |
|
#4
|
||||
|
||||
|
I've also tried...
Code:
IF ((SELECT COUNT(*) FROM table1) = 0) THEN -- some SQL here #LOG test END IF |
|
#5
|
||||
|
||||
|
I'm guessing #LOG isnt processed by the SQL and just runs no matter what.
|
|
#6
|
||||
|
||||
|
you might want to begin by telling us which DBMS you're running
and how/where you are executing that SQL and whether you are using an application programming language where possibly you should be doing the IF logic instead |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > If-statements and count |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|