Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Comparison in WHERE statement

Author  Topic 

uttam548
Starting Member

12 Posts

Posted - 2008-09-10 : 05:25:27
I need to filter out the result according to the @ReportType variable.
Here is the query i have used

IF @ReportType = 'ANOTHER'
SELECT Invoice.Office, Invoice.TotalCost, Invoice.InvoiceDate
FROM dbo.Invoice
WHERE Invoice.TransactionType = 'ANOTHER'
ELSE
SELECT Invoice.Office, Invoice.TotalCost, Invoice.InvoiceDate
FROM dbo.Invoice
WHERE Invoice.TransactionType <> 'ANOTHER'
ORDER BY Invoice.CurrencyID, Invoice.InvoiceDate

How can I use comparison in WHERE statement so that i don't have to write the select statement twice in my query?

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-09-10 : 07:02:10
[code]WHERE (@ReportType = 'ANOTHER' AND Invoice.TransactionType = 'ANOTHER')
OR (@ReportType <> 'ANOTHER' AND Invoice.TransactionType <> 'ANOTHER')[/code]
Go to Top of Page

dexter.knudson
Constraint Violating Yak Guru

260 Posts

Posted - 2008-09-10 : 08:04:19
Hi Uttam, Hope you don't mind a little digression. Are you working in Nepal? I'd be interested to hear what you are doing with SQL Server there....obviously something to do with invoices! Is there much SQL Server work? What's the pay like?
Go to Top of Page

uttam548
Starting Member

12 Posts

Posted - 2008-09-11 : 03:56:18
Hi Dexter,yeah, i'm working in an outsourcing company in Nepal.We are using SQL server as backend database for developing Inventory management system.Most of the new projects here use SQL server as backend.
I need to write a single SELECT statement for the above mentioned query. Can you suggest me?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-11 : 05:43:26
quote:
Originally posted by uttam548

Hi Dexter,yeah, i'm working in an outsourcing company in Nepal.We are using SQL server as backend database for developing Inventory management system.Most of the new projects here use SQL server as backend.
I need to write a single SELECT statement for the above mentioned query. Can you suggest me?


Did you try bjoerns's query?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -