cheap script to bcp out subset of data 
Author Message
 cheap script to bcp out subset of data

Someone was asking how to bcp out a subset of data without using
a temporary table.

Here is a very quick and dirty script written in sybperl to generate
a flat file that bcp in should eat just fine.  Most of the code
was shamelessly stolen from Michael Peppler.  Enjoy.

#!/devel/gnu/bin/sybperl

        require 'sybperl.pl';
        require 'getopts.pl';

        do Getopts('u:p:d:s:a:b:o');

        $opt_u = 'sa' unless $opt_u;            # u = user id
        $opt_s = $ENV{DSQUERY} unless $opt_s;   # s = server
        $opt_d = "master" unless $opt_d;      # d = database
        $opt_a = ":" unless $opt_a;           # a = field terminator
        $opt_b = "\n" unless $opt_b;          # b = line terminator
        $opt_o = "sbcp.out" unless $opt_o;    # o = output file

        open(OUTPUT, ">sbcp.out") || die "Can't open $opt_o: $!";

        if ( $opt_p eq "" )
        {
                system("stty -echo");
                print "password for $opt_u: ";
                chop($opt_p = <>);
                system("stty echo");
                print "\n";
        }

        $dbproc = &dblogin($opt_u, $opt_p) && die "Can't login.";
        &dbuse($opt_d) || die "Can't use database $opt_d";

        print "Now, enter your sql query, end it with go\n";
        print "on a blank line.\n";
        print "> ";

        while (<>)
        {
                chop;
                &dbcmd($dbproc, $_) if ( $_ ne "go" );
                last if $_ eq "go";
                print "> ";

        }

        &dbsqlexec($dbproc) || die "command line failed, sorry.";

        while(($stat = &dbresults($dbproc)) != $NO_MORE_RESULTS)
        {
                die "dbresults failed" if $stat == $FAIL;

                {


                }

        }



Sat, 01 Feb 1997 06:59:27 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Computers CHEAP CHEAP CHEAP

2. Calculated subtotal of a subset of a subset in a file

3. Need Windows Scripting Host script to BCP a file using SQL-DMO

4. NO CHEAP CHEAP CD WAREZ

5. BCP - Unexpexted EOF encountered in BCP data-file

6. ODBC, BCP Error: Unable to open BCP host data-file

7. ODBC, BCP Error: Unable to open BCP host data-file

8. Help BCP Unexpected EOF in BCP data-file.

9. bcp: unexpected EOF in bcp data file

10. BCP - Unexpexted EOF encountered in BCP data-file

11. data security by limited record subset


 
Powered by phpBB® Forum Software