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
 General SQL Server Forums
 New to SQL Server Programming
 Query doubt

Author  Topic 

anuraag205
Yak Posting Veteran

58 Posts

Posted - 2012-09-24 : 03:27:07
On the 13 th line of this query i need to get results of fk_statusid=3 and 5. Here below am able to get only 3.... how can i get 5 also???

=========================================================================================================================================== Declare @GroupCode as varchar(10)
Declare @StartDate as varchar(12)
Declare @EndDate as varchar(12)
Declare @SiteID as varchar(3)

Set NOCOUNT OFF

Set @StartDate='01/sep/2012'
Set @EndDate='01/oct/2012'
Set @SiteID = 'UW'

Select tblCountry.CountryName, COUNT(tblInvoice.InvoiceNumber) AS [Total Bookings]
FROM tblInvoice INNER JOIN
tblClient ON tblInvoice.fk_ClientID = tblClient.pk_ClientID INNER JOIN
tblCountry ON tblClient.fk_CountryID = tblCountry.pk_CountryID
where BookingDate between @StartDate and @EndDate and siteid=@SiteID and fk_statusid=3
--and tblInvoice.fk_introducerid=798--For PPC Booking
--and tblInvoice.fk_introducerid=801--For Shareasale Boikoin
--and tblInvoice.fk_introducerid=802--For Yahoo SM
--and tblInvoice.fk_introducerid=803--For MSN AD Center
--and tblInvoice.fk_introducerid=807--For PSMAmericaCarRental
---and tblInvoice.fk_statusid=3
---and tblInvoice.dbo.tblVehicleCategory.pk_CategoryID=193
--and tblInvoice.invoicenumber in ('UW005234','UW005244','UW005273')
--order by tblInvoice.invoicenumber
GROUP BY tblCountry.CountryName
ORDER BY COUNT(tblInvoice.InvoiceNumber)desc
===========================================================================================================================================

Thanks

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-09-24 : 03:39:59
Hi anuraag,

USe IN instead of = operator

fk_statusid IN (3,5)

--
Chandu
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-09-24 : 03:40:00
Hi anuraag,

USe IN instead of = operator

fk_statusid IN (3,5)

--
Chandu
Go to Top of Page

anuraag205
Yak Posting Veteran

58 Posts

Posted - 2012-09-24 : 03:45:57
Thanks Bandi...That Worked...

Thanks
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-09-24 : 03:46:34
Welcome

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-24 : 13:13:03
if you want it make it future maintainable and scalable better approach would be to use a table to hold id valuess along with descriptions and then add a join to it in above query. by doing this you dont have worry about hardcoding id values and keeping on changing the query each time an id gets added,modified or removed. whatever changes happens, you just need to do single DML (Insert,update,delete) operation on your table rather than on the query.
If its one time activity, then above approach is good enough

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -