gjsaturday
Technical User
a query would be written this way...
SELECT (SELECT Code
FROM Location AS A
WHERE A.ID = Location.Parent) AS typecode,
(select CODE from type where Location.type=type.ID) as tCode,dbrderRecommendation.Amount, dbrderRecommendation.OrderDate,
dbrderRecommendation.ShipDate
FROM dbrderRecommendation
INNER JOIN dbo.Location ON dbrderRecommendation.ttID = dbo.Location.ID
WHERE DATEDIFF(dd, dbrderRecommendation.OrderDate, GETDATE()) = 0 AND (dbrderRecommendation.OrderType = 0)
when it can easily be accomplished this way...
select type.code, d.code, j.Amount, j.OrderDate, j.ShipDate
from
location t
inner join type d on t.type = d.id
inner join OrderRecommendation j on t.id = j.typetid and j.orderdate = convert(varchar,(getdate()),101)
inner join location type on t.parent = type.id
I don't know who wrote the first one to ask if there was a reason for writing it that way.
Thanks in advance.
SELECT (SELECT Code
FROM Location AS A
WHERE A.ID = Location.Parent) AS typecode,
(select CODE from type where Location.type=type.ID) as tCode,dbrderRecommendation.Amount, dbrderRecommendation.OrderDate,
dbrderRecommendation.ShipDate
FROM dbrderRecommendation
INNER JOIN dbo.Location ON dbrderRecommendation.ttID = dbo.Location.ID
WHERE DATEDIFF(dd, dbrderRecommendation.OrderDate, GETDATE()) = 0 AND (dbrderRecommendation.OrderType = 0)
when it can easily be accomplished this way...
select type.code, d.code, j.Amount, j.OrderDate, j.ShipDate
from
location t
inner join type d on t.type = d.id
inner join OrderRecommendation j on t.id = j.typetid and j.orderdate = convert(varchar,(getdate()),101)
inner join location type on t.parent = type.id
I don't know who wrote the first one to ask if there was a reason for writing it that way.
Thanks in advance.