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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing conditions

Status
Not open for further replies.

digimortal

Programmer
Oct 12, 2003
28
TR
I have problem like this:
there are two fields in the table, type, duedate and postdate.

If type (field) is X then query should looklike this:

Select * from Table where duedate < 'DATE'

else query should looklike this:

Select * from Table where postdate < 'DATE'

Can I do it in one query? because I'm using it with reporting services...
 
Doesn't the type field have a value for each row in the table?

Did you mean to say?
Code:
select     type, 
           case when type = 'x' then duedate else postdate end
from       Table

Best Regards,
AA
 
Maybe you meant this:
Code:
Select *
From   Table
Where  type = 'X' and duedate < 'Date'
       OR type != 'X' and postdate < 'Date'

Regards,
AA
 
digi,

If you're using this with Reporting Services, I would create a Proc for your dataset and then use one of the codes as listed above OR do the following.

Dataset = Exec MyProc @Type, @MyDate

Code:
Create Procedure MyProc
(@Type char(1), @MyDate datetime)
AS
If @Type = X
  Begin
    Select * from Table where duedate < @MyDate
  End
Else
  Begin
    Select * from Table where postdate < @MyDate
  End

I used MyDate as the variable name because I think Date is a reserved keyword.

Does that help?




Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top