As I said I have no experience of sqlcmd. However I've used DBD::ODBC for ages and know this fairly well. As I've not used sqlcmd I'm not sure what you are expecting as output in the output file. If your input file contains a number of SQL select statements and you want to see result-sets in the output file I'd need to know how you expect the output in the output file. Simplistically I'd say you open a DBI connection to your database, read a line at a time from your input file and feed it into DBI's prepare then execute and lastly (and this is where it is difficult to say) call something like fetchrow_arrayref and Data::Dumper the result into your output file.

If your problem is that each line in the input file selects a different result-set (i.e., different columns) then you'd need to say how you would like the results to look. Certainly I cannot guess this for you.


In reply to Re^3: using dbi to run sql file by mje
in thread using dbi to run sql file by aksaravanan

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.