With what you've described, I can't see what would cause your problem. I tried it.

(Since you didn't provide any schema or sample data I invented some.)

-- T-SQL create table milestones ( [id] int not null, project_ID char(1) null, title char(1), details char(1) null, date_expected smalldatetime null, date_completed smalldatetime null ) go insert into milestones values (1,'a','a','a','2004-01-01', '2004-01-01 +') insert into milestones values (1,'b','a','a','2004-01-02', '2002-01-01 +') insert into milestones values (1,'c','a','a','2004-02-10', null) insert into milestones values (1,'d','a','a', null, null) insert into milestones values (1,'e','a','a','2004-11-11', null) go select * from milestones go -- Milestones now contains - id project_ID title details date_expected date_compl +eted ----------- ---------- ----- ------- ---------------------- ---------- +--------- 1 a a a 2004-01-01 00:00:00 2004-01-01 + 00:00:00 1 b a a 2004-01-02 00:00:00 2002-01-01 + 00:00:00 1 c a a 2004-02-10 00:00:00 NULL 1 d a a NULL NULL 1 e a a 2004-11-11 00:00:00 NULL (5 row(s) affected) # Perl code use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:ODBC:driver=SQL Server;database=pubs;serve +r=(local)", 'sa', 'mypassword') or die "can't connect"; my $q = qq{ select ID, project_ID, title, details, DATEPART(dd, date_expected), DATEPART(mm, date_expected), DATEPART(yyyy, date_expected), DATEPART(dd, date_completed), DATEPART(mm, date_completed), DATEPART(yyyy,date_completed), is_complete = case when date_completed is null then 0 else 1 end from MILESTONES where ID = 1 }; my $sth= $dbh->prepare($q); $sth->execute; while (my @row = $sth->fetchrow_array) { $_ ||= 'NULL' for @row; print "@row\n"; } $sth->finish; $dbh->disconnect; __END__ d:\tmp>Test.pl 1 a a a 1 1 2004 1 1 2004 1 1 b a a 2 1 2004 1 1 2002 1 1 c a a 10 2 2004 NULL NULL NULL NULL 1 d a a NULL NULL NULL NULL NULL NULL NULL 1 e a a 11 11 2004 NULL NULL NULL NULL

In reply to Re: SQL Server CAST problem using CASE with DBD::ODBC by EdwardG
in thread SQL Server CAST problem using CASE with DBD::ODBC by simon.proctor

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.