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.
| 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 usedIF @ReportType = 'ANOTHER'SELECT Invoice.Office, Invoice.TotalCost, Invoice.InvoiceDateFROM dbo.Invoice WHERE Invoice.TransactionType = 'ANOTHER' ELSESELECT Invoice.Office, Invoice.TotalCost, Invoice.InvoiceDateFROM dbo.Invoice WHERE Invoice.TransactionType <> 'ANOTHER' ORDER BY Invoice.CurrencyID, Invoice.InvoiceDateHow 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] |
 |
|
|
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? |
 |
|
|
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? |
 |
|
|
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?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|