Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Im using operating system: Windows XP
database driver: DBD::ODBC
i want give customer name as input to the procedure (Ex-procedure name) and it checks whether the name is already present in the table and insert the customer name if it is not in the table.
here is sample code
#!/usr/local/bin/perl use DBI; use DBD::ODBC; my $dbh = DBI->connect("dbi:ODBC:dsnentry", '', '', {PrintError => 0}) +; die "Unable for connect to server" unless $dbh; $dbh->{odbc_SQL_ROWSET_SIZE} = 2; $query="Exec ex 'habibrahman'"; my $result=$dbh->prepare($query) or print "cannot prepare" ; $result->{LongReadLen}=512*1024; $result->{LongTruncOk}=1; $result->execute() or print $result->errstr();

and here is my procedure

create procedure ex (@name varchar(200)) as declare @cust_id int select @cust_id=cust_id from X where cust_name=@name if(@cust_id='') begin insert into x(cust_name) values(@name) end GO

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: sql server procedure
by EdwardG (Vicar) on Jul 26, 2006 at 07:50 UTC

    if not exists (select cust_id from X where cust_name = @name) insert into X(cust_name) values (@name)

    Beware race conditions