PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: how to do this in perl
Date: Jun 18 1998 4:38PM

Travis Lee writes:
 > hi,
 > 
 > i'm trying to test the existence of data from a table then do something
 > accordingly.
 > how can i get the status value from this query in perl?
 > this is not a stored proc.
 > 
 > if(exists (select * from atable))
 > 	select 0
 > else
 > 	select 1
 > 
 > any suggestions?

One simple way to do this would be:

$dat = $dbh->sql("
if(exists (select * from atable))
 	select 0
 else
 	select 1
");

if($dat->[0]->[0] == 1) {
	do your stuff
}

Alternatively, if you know what you need to do you can build the whole 
SQL and then send it off in one go:

$data = $dbh->sql("
if exists ( select * from atable )
  begin
	-- add appropriate code to be executed if data exists
  end
else
  begin
	-- etc
  end
");

By using appropriate variables, etc you can build the SQL so that the
right thing gets executed, and retrieve any results in $data...

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@datamig.com    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com