Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 *

Author  Topic 

wtrihardiny
Starting Member

12 Posts

Posted - 2008-04-25 : 15:58:14
*

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-04-25 : 16:21:26
if you were going to format it in sql, the datetime field has a minumum value of 01/01/1900, so the code would be


case when b.ClaimStatusCode <> 3 then cc.BenefitEndDate
else convert(datetime,'01/01/1900',102)
end as MaxBenefitDate


In crystal you can use vb so you probably don't need to do anything to the sql format and can leave the value as null, then use this code.

iif(MaxBenefitDate is Dbnull.value,'00/00/0000',cstr(MaxBenefitDate))
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-04-25 : 16:32:15
see my post
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-04-25 : 16:36:31
You can also do all formating in sql, but convert to char rather then a datetime


case when b.ClaimStatusCode <> 3 then convert(char(10),cc.BenefitEndDate,110)
else '00-00-0000'
end as MaxBenefitDate
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-04-25 : 16:40:26
IF crystal accepts vb, then you should be using "(" and ")", not "{" and "}"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 16:42:44
Maybe table with alias B is LEFT-JOINed?
If so the check when NULL behaves differently.

case b.ClaimStatusCode
when 3 then '00-00-0000'
else convert(char(10), cc.BenefitEndDate, 110)
end as MaxBenefitDate



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-04-25 : 16:44:23
I tested the case statements and they both are working. make sure you are implementing correctly. Here is a sample.

declare @Mydate1 as datetime, @Mydate2 as datetime
set @Mydate1 = getdate()

select case when not @Mydate1 is null then convert(char(10),@MyDate1,110) else '00-00-0000' end as mydate
select case when not @Mydate2 is null then convert(char(10),@MyDate2,110) else '00-00-0000' end as mydate

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 16:49:05
If it didn't work, what have you learned by this?

Always post full query if you want help.
Otherwise it is like going to the doctor for chestpains, and not telling your doctor that you have smoked 600 cigarettes the last tw days, drunk 2 bottles of vodka and carried heavy things the day before.
I think your doctor would like to have all information in order to give a solution, right?


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 17:04:17
The problem is not the CASE construct. Your problem is all the WHERE in wrong place.
Try this
Select		b.BaseClaimID,
p.BaseClaimID,
p.ClaimPolicyID,
c.CedingCompanyCode,
c.ClientLongName,
stc.ClaimStatusDesc,
dbo.FormatTaxID(pt.TaxID, pt.TaxIDTypeCode, @SSNMask),
pt.LastName,
pt.FirstName,
0,
g.OffsetAmt,
0,
g.StartDate,
g.EndDate,
otc.OverpaymentDesc,
o.OverPaymentAmt,
p.OverPaymentBalance,
p.OverPaymentTotalOwedAmt,
0,
cd.offsetmethodcode,
o.calculationdate,
b.claimstatuscode,
cc.benefitenddate,
case
when b.ClaimStatusCode <> 3 then CONVERT(VARCHAR(10), cc.BenefitEndDate, 110)
else '00-00-0000' end as MaxBenefitDate
from ClaimOverPayment o (nolock)
Left Join ClaimPolicy p (nolock) on p.ClaimPolicyID = o.ClaimPolicyID
AND p.OverPaymentBalance > 0
Left Join ClaimOffset f (nolock) on f.OwnerID = p.ClaimPolicyID
and f.OwnerTypeCode = 72
And f.OffsetTypeCode = 1
And f.OffsetMethodCode = 0
Left Join ClaimOffset g (nolock) on g.OwnerID = p.ClaimPolicyID
and g.OwnerTypeCode = 72
and g.OffsetTypeCode = 4
and g.offsetmethodcode = 0
Left Join BaseClaim b (nolock) on b.BaseClaimID = p.BaseClaimID
AND (b.BaseClaimID = @ClaimNo or @ClaimNo = '')
And (b.ClaimStatusCode = @StatusID or @StatusID = 0)

Left Join Party pt on pt.PartyID = b.InsuredPartyID
And pt.AsOfDate = '5/9/2999'
Left Join cdClaimStatusCodes stc (nolock) on stc.ClaimStatusCode = b.ClaimStatusCode
Left Join cdClaimOverpaymentTypeCodes otc (nolock) on otc.OverpaymentTypeCode = o.OverpaymentTypeCode
Left Join dbo.AceCedingCompanies c on c.CedingCompanyCode = b.CedingCompanyCode
And (c.CedingCompanyCode = @CedingCompanyCode or @CedingCompanyCode = '')
Left Join cdClaimOffsetMethodCodes cd (nolock) on cd.offsetmethodcode = g.offsetmethodcode
Left Join ClaimCoverage cc on cc.ClaimPolicyID = p.ClaimPolicyID
Order By p.BaseClaimID

And make the MaxBenefitDate a VARCHAR(10) instead of DATETIME in your temp table!
Because now the Maxbenefit is not a date anymore, it is just a string of digits and hyphens.
Your original error is about just this. "00-00-0000" is not a valid date in SQL Server.
So it cannot be converted to a datetime columns in your temp table.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-18 : 11:12:07
why did you edit your original question?
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2008-11-18 : 14:46:05
I think a better question is, why is someone allowed to edit a 6 and a half month old post?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-18 : 16:12:23
Also see
http://education.sqlfarms.com/education/ShowPost.aspx?PostID=1606
http://education.sqlfarms.com/education/ShowPost.aspx?PostID=1646
http://education.sqlfarms.com/education/ShowPost.aspx?PostID=1661
http://education.sqlfarms.com/education/ShowPost.aspx?PostID=1662
http://education.sqlfarms.com/education/ShowPost.aspx?PostID=1711


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -