473,395 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Any SQL statements to return no records found?

170 100+
hey guys,

just wanna know if there's any SQL statements that will help u to determine if a match is found when u use the SELECT statement?
so if the SELECT statement don't match anything it will return false statement or something like that
May 23 '08 #1
6 4914
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. SELECT 1 FROM tablename WHERE condition
May 23 '08 #2
ck9663
2,878 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. SELECT 1 FROM tablename WHERE condition

To extend this code:
Expand|Select|Wrap|Line Numbers
  1. if exists(select 1 from yourtable where yourcondition)
  2. begin
  3.   do this
  4.   and this
  5.   and this
  6. end
  7. else
  8. begin
  9.    do this
  10.    and this
  11.    and that
  12. end
You only need to enclosed it with BEGIN..END if there are two or more statements that needs to be executed in IF or in ELSE.

-- CK
May 23 '08 #3
poolboi
170 100+
i'm not sure if the syntax is right
but i think the exists should be enclose within the brackets
my code as said above is

Expand|Select|Wrap|Line Numbers
  1.  
  2.    if (exists SELECT 1 FROM `mml log` WHERE Commands LIKE '%$IMSI%')
  3.    begin
  4.       do  
  5.         while(my $ref = $sth->fetchrow_arrayref){
  6.  
  7.                        print "<tr></tr>";
  8.                        for (my $i=0; $i<$numFields; $i++){
  9.                         print "<td>", $$ref[$i], "</td>\n";  
  10.  
  11.    }
  12. }
  13. end  
  14. else
  15.     begin
  16.      do
  17.         print "<p>Sorry! No Records have been found!</p>";
  18.    end
  19.  
  20.  
and i'm getting errors like

a) exist arguement is not a hash or an array
b) number found where operator expected near "SELECT 1" (Do you need to predeclare SELECT?)
May 26 '08 #4
Delerna
1,134 Expert 1GB
your if should be like

Expand|Select|Wrap|Line Numbers
  1. if exists(SELECT 1 FROM `mml log` WHERE Commands LIKE '%$IMSI%')
  2.  
  3.  
also what is `mml log`

if it is a table or view name then it should be like this

Expand|Select|Wrap|Line Numbers
  1. if exists(SELECT 1 FROM [mml log] WHERE Commands LIKE '%$IMSI%')
  2.  
  3.  
May 26 '08 #5
poolboi
170 100+
hm...if i put the exists outside i'm still getting a synta error
i'm using perl anyway to process this code
May 26 '08 #6
ck9663
2,878 Expert 2GB
You're mixing PERL and SQL. Check with PERL forum how to connect to sql-server using PERL and how to define data object in PERL and how to process it.Then you pass your select on that connection and process it.

-- CK
May 26 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
16
by: klowe | last post by:
Hi, I'm an Access newbie and need to update an Access database from a web application. I'll need to add new records and also update existing ones. What I was thinking of doing is have my web app...
24
by: sureshjayaram | last post by:
In some functions where i need to return multiple error codes at multiple places, I use multiple return statements. Say for ex. if (Found == 1) { if (val == -1) return error1; } else { if...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
1
by: MackTheKnife | last post by:
I have the following 3 SQL statements that need to be combined, if possible. The output of one feeds the input of the next. I need to view all of the defined output fields (the output needs to be...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
0
by: BA | last post by:
I posted on this once before and could not get a solution, I am hoping someone can help. I have a very strange code debug behavior that I cannot make heads or tails of: I have c# code being...
3
by: =?Utf-8?B?WFNsZXI=?= | last post by:
I have some code that works fine, except for the fact that it has a lot of embedded if statements. I don't think that this would be practice code, but I wanted to tap into the knowledge of this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.