As you know my original thought was to go down the create view/bcp data out route as you have suggested also. The problem is that I need to run a regex over the extracted data and I figure it's easier to do this via perl than inside sql given the complexities of what I need to do.
Here is the test code I ended up with (some of which you may recognise ). This is taking the pure select route rather than the create view/bcp route. However I have a problem I getting the regex to work.

This is a snapshot of the dataset 92 1 24 Dec 20 2005 2:14PM 1 14 2 sa tempdb select * from sysuser +s 92 1 24 Dec 20 2005 2:14PM 1 14 2 sa tempdb select * from master. +.sysprocesses 92 1 24 Dec 20 2005 2:14PM 1 14 2 sa tempdb select * from sysuser +s 92 1 24 Dec 20 2005 2:14PM 1 14 2 sa tempdb select * from master. +.sysprocesses 92 1 25 Dec 20 2005 2:14PM 1 14 2 sa tempdb use tempdb 92 1 25 Dec 20 2005 2:14PM 1 14 2 sa tempdb select * from sysuser +s 92 1 26 Dec 20 2005 2:14PM 1 14 2 sa tempdb use tempdb 92 1 26 Dec 20 2005 2:14PM 1 14 2 sa tempdb select @@version 92 1 26 Dec 20 2005 2:14PM 1 14 2 sa tempdb COMMIT TRAN 92 1 26 Dec 20 2005 2:14PM 1 14 2 sa tempdb create table #ttt (fo +o varchar(20), bar int) 92 1 26 Dec 20 2005 2:14PM 1 14 2 sa tempdb insert #ttt values('a + string', 1) 92 1 26 Dec 20 2005 2:14PM 1 14 2 0001fb520002 sa tempdb insert #t +tt values('another string', 2) 92 1 26 Dec 20 2005 2:14PM 1 14 2 0001fb520002 sa tempdb insert #t +tt values('foodiboo', 3) 92 1 26 Dec 20 2005 2:14PM 1 14 2 0001fb520002 sa tempdb ROLLBACK TRAN Here's the code my $lastrunt = "Dec 20 2005 9:00AM"; my @sqlcmd; $dbh->do("use sybsecurity"); $sth=$dbh->prepare("select * from sysobjects where name like 'sysaudit +s_%'"); $sth->execute; while ($data = $sth->fetch) { push @sqlcmd,"select extrainfo from @$data where suid in (select + a.suid from master..syslogins a, master..s ysloginroles b where b.srid=0 and a.suid=b.suid and a.suid not in (1,8 +))) and event=92 and eventtime > '$lastrunt'"; push @sqlcmd," union"; } pop @sqlcmd; $sth=$dbh->prepare("@sqlcmd"); $sth->execute; while ($data = $sth->fetch) { # print "@$data\n"; if($data =~ /create/) { print "@$data\n"; } }
I was trying to only pick out the create statements but I don't get anything. If I uncomment the print then the above dataset is returned.

I'm trying to get to grips with Perl but can't figure out what is wrong with my regex statement ?


In reply to Re^2: Perl or SQL ? by Anonymous Monk
in thread Perl or SQL ? by Anonymous Monk

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.