March 19, 2008 at 1:06 am
Hi Folks,
I really wonder to know how to correct the mistake below.How can I use CASE statement?????
Please help
select b.SiparisNo,
datediff(day,a.dteTeslimTarihi,b.OnayTarihi) as 'Gun Farki',
substring(c.sKodu,1,12) as ModelKodu,
CASE datediff(day,a.dteTeslimTarihi,b.OnayTarihi)
when datediff(day,a.dteTeslimTarihi,b.OnayTarihi)>0 Then 2 else 0
end as
from Coll2005.dbo.tbSiparis a
INNER JOIN
TblReklamasyonOnay_V1 b on a.lSiparisNo=b.siparisno
INNER JOIN
Coll2005.dbo.tbStok c on c.nstokID=a.nstokID and b.ModelNo=substring(c.sKodu,1,12) collate TURKISH_CI_AS
where substring(c.sKodu,1,12) like '8%'
group by b.siparisno,datediff(day,a.dteTeslimTarihi,b.OnayTarihi),substring(c.sKodu,1,12)
March 19, 2008 at 2:51 am
CASE when datediff(day,a.dteTeslimTarihi,b.OnayTarihi)>0 Then 2 else 0 end
http://transactsql.blogspot.com/
March 19, 2008 at 4:17 am
Thank you very much
March 20, 2008 at 9:01 am
erdem (3/19/2008)
Hi Folks,I really wonder to know how to correct the mistake below.How can I use CASE statement?????
Please help
select b.SiparisNo,
datediff(day,a.dteTeslimTarihi,b.OnayTarihi) as 'Gun Farki',
substring(c.sKodu,1,12) as ModelKodu,
CASE datediff(day,a.dteTeslimTarihi,b.OnayTarihi)
when datediff(day,a.dteTeslimTarihi,b.OnayTarihi)>0 Then 2 else 0
end as
from Coll2005.dbo.tbSiparis a
INNER JOIN
TblReklamasyonOnay_V1 b on a.lSiparisNo=b.siparisno
INNER JOIN
Coll2005.dbo.tbStok c on c.nstokID=a.nstokID and b.ModelNo=substring(c.sKodu,1,12) collate TURKISH_CI_AS
where substring(c.sKodu,1,12) like '8%'
group by b.siparisno,datediff(day,a.dteTeslimTarihi,b.OnayTarihi),substring(c.sKodu,1,12)
Note that TSQL has two types of CASE statement:
1. Simple CASE: CASE datediff(day,a.dteTeslimTarihi,b.OnayTarihi) when 0 then 0 else 2 end
2. Searched CASE: CASE when datediff(day,a.dteTeslimTarihi,b.OnayTarihi)>0 Then 2 else 0 end
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply