Hi friends,

+++++++++++School(B):Students++++++++++

No.of students:120

No.of classes:2

No.of teachers:5

Hostel facility:available

++++++++++School(G):Students+++++++++++

No.of students:300

No.of classes:3

No.of teachers:10

i have got lot of data like this. i need to insert it into SQLServer by using perl programming

I need to insert into sql_Table by

Type of school,No.of students,No.of classes,No.of Teachers,Hostelfacility

pls anyone help me to align data into SQL

i already tried this coding;pls give some other way to enhance my coding

#MsSQL Server2008 #!/usr/bin/perl use strict; use DBI; my $FIRST="+++++++++++School(B)"; my $SECOND="+++++++++++School(G)"; my $j=0; my $dbh = DBI->connect('dbi:ODBC:SQLServer', undef, undef, {PrintError + => 0, RaiseError =>0}); my $sth1 = $dbh->prepare("CREATE TABLE test11 ('$Type[0]','$Students[1 +]','$class[2]','$Teachers[3]','$hostel[4]')"); + $sth1->execute; foreach $line (<FILE>) { chomp $_; ($event[$kk],$data[$kk])=split(/: /,$line); $l= ++$kk; } while($j<=$l) { if($event[$j] eq $FIRST) { $Type[0]="BOYS"; my $x=1; ++$j; } if($event[$j] eq $SECOND) { $Type[0]="GIRLS"; ++$j; } if($event[$j] =~ m/^No.of Stud /ig) { $Students[1]=$data[$j]; ++$j; } if($event[$j] =~ m/^No.of class /ig) { $class[2]=$data[$j]; ++$j; } if($event[$j] =~ m/^No.of teach/ig) { $teachers[3]=$data[$j]; ++$j; } if($event[$j] =~ m/^Hostelfacility/ig) { $hostel[4]=$data[$j]; ++$j; } my $sth = $dbh->prepare("insert into test11 values('$Type[0]','$Studen +ts[1]','$class[2]','$Teachers[3]','$hostel[4]')"); $sth->execute; ++$j; } #i need to enhance my coding efficiency pls help me #Thanks in advance

In reply to Data insert into SQL Server? by sowraaj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.