| 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 becase when b.ClaimStatusCode <> 3 then cc.BenefitEndDateelse 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)) |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-04-25 : 16:32:15
|
| see my post |
 |
|
|
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 datetimecase when b.ClaimStatusCode <> 3 then convert(char(10),cc.BenefitEndDate,110)else '00-00-0000'end as MaxBenefitDate |
 |
|
|
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 "}" |
 |
|
|
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" |
 |
|
|
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 datetimeset @Mydate1 = getdate()select case when not @Mydate1 is null then convert(char(10),@MyDate1,110) else '00-00-0000' end as mydateselect case when not @Mydate2 is null then convert(char(10),@MyDate2,110) else '00-00-0000' end as mydate |
 |
|
|
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" |
 |
|
|
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 thisSelect 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 MaxBenefitDatefrom ClaimOverPayment o (nolock)Left Join ClaimPolicy p (nolock) on p.ClaimPolicyID = o.ClaimPolicyID AND p.OverPaymentBalance > 0Left Join ClaimOffset f (nolock) on f.OwnerID = p.ClaimPolicyID and f.OwnerTypeCode = 72 And f.OffsetTypeCode = 1 And f.OffsetMethodCode = 0Left Join ClaimOffset g (nolock) on g.OwnerID = p.ClaimPolicyID and g.OwnerTypeCode = 72 and g.OffsetTypeCode = 4 and g.offsetmethodcode = 0Left 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.ClaimStatusCodeLeft Join cdClaimOverpaymentTypeCodes otc (nolock) on otc.OverpaymentTypeCode = o.OverpaymentTypeCodeLeft Join dbo.AceCedingCompanies c on c.CedingCompanyCode = b.CedingCompanyCode And (c.CedingCompanyCode = @CedingCompanyCode or @CedingCompanyCode = '')Left Join cdClaimOffsetMethodCodes cd (nolock) on cd.offsetmethodcode = g.offsetmethodcodeLeft Join ClaimCoverage cc on cc.ClaimPolicyID = p.ClaimPolicyIDOrder 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" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-18 : 11:12:07
|
| why did you edit your original question? |
 |
|
|
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.aspxLearn SQL or How to sell Used CarsFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|