Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Date Fields formula or something 1

Status
Not open for further replies.

codrutza

Technical User
Mar 31, 2002
357
IE
I work with SQL Server 2000.
I need to write in a SP:

SELECT ….FROM…
WHERE
DepArr>=@DateStart and DepArr<@DateEnd

Where DepArr:
If table.type=’imp’ then DepArr=table.ArrDate
Else if table.type=’exp’ then DepArr=table.DepDate

Pls help
 
You can use two ideas:
Code:
select .. FROM
where (Table.Type = 'imp' and Table.ArrDate >=@DateStart and Table.ArrDate < @DateEnd) OR (Table.Type = 'exp' and Table.DepDate >=@DateStart and Table.DepDate < @DateEnd)

Alternative solution
Code:
select * from 
(select .., case when Type = 'imp' then ArrDate 
when Type = 'exp' then DepDate end) as DepArr FROM .. ) 
Derived where Derived.DepArr >=@DateStart and DepArr <@DateEnd

You need to test the performance.

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top