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)
 Help with This count query

Author  Topic 

ivra
Starting Member

18 Posts

Posted - 2009-03-17 : 06:23:39
Hi,

I always get this error message when I run my script.


SELECT Count(UserInfo.user_id) AS CountOfuser_id, UserInfo.country
FROM UserInfo LEFT JOIN ((ListingInfo INNER JOIN
CheckoutInfo ON ListingInfo.item_id =
CheckoutInfo.item_id) ON UserInfo.user_id =
ListingInfo.item_id = ListingDisputeInfo.item_id) ON
UserInfo.user_id = ListingInfo.seller_id
GROUP BY UserInfo.country
HAVING (((Count(UserInfo.user_id)) In (SELECT User_ID FROM
month(auct_end_date)=10)) AND ((UserInfo.country)='UK')
AND Payment_mthd_lookup.payment_mthd_desc='PayPal'
AND ((Count(ListingDisputeInfo.item_id))>1))

Error Message:

Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'ON'.
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near 'Count'.
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '='.

Can someone let me know what's wrong with the script. thanks

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-17 : 06:35:31
SELECT Count(UserInfo.user_id) AS CountOfuser_id,
UserInfo.country
FROM UserInfo
LEFT JOIN
ListingInfo ON UserInfo.user_id = ListingInfo.seller_id
INNER JOIN
CheckoutInfo ON ListingInfo.item_id = CheckoutInfo.item_id
GROUP BY UserInfo.country
HAVING (Count(UserInfo.user_id) > value

in having clause also u didn't mentioned tablename
and if u use the condition u will get the error as invalid value in group by clause
how will be count value in userid value?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2009-03-17 : 06:39:12
quote:
Originally posted by ivra

Hi,

I always get this error message when I run my script.


SELECT Count(UserInfo.user_id) AS CountOfuser_id, UserInfo.country
FROM UserInfo LEFT JOIN (ListingInfo INNER JOIN
CheckoutInfo ON ListingInfo.item_id =
CheckoutInfo.item_id) on UserInfo.user_id = ListingInfo.seller_id
Left JOIN ListingDisputeInfo
ON ListingInfo.item_id = ListingDisputeInfo.item_id

GROUP BY UserInfo.country
HAVING (((Count(UserInfo.user_id)) In (SELECT User_ID FROM
month(auct_end_date)=10)) AND ((UserInfo.country)='UK')
AND Payment_mthd_lookup.payment_mthd_desc='PayPal'
AND ((Count(ListingDisputeInfo.item_id))>1))

Error Message:

Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'ON'.
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near 'Count'.
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '='.

Can someone let me know what's wrong with the script. thanks



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-17 : 11:17:06
i cant understand what you're trying to achieve by this query. whats the purpose of below condition?
HAVING (((Count(UserInfo.user_id)) In (SELECT User_ID FROM
month(auct_end_date)=10)) AND ((UserInfo.country)='UK')
AND Payment_mthd_lookup.payment_mthd_desc='PayPal'
AND ((Count(ListingDisputeInfo.item_id))>1))

why are you comparing count value to user_Id field?
Go to Top of Page

ivra
Starting Member

18 Posts

Posted - 2009-03-18 : 04:19:39
thanks for the feedback.I just realized that I dont need to include the HAVING clause in my script. thanks all for the help.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-18 : 04:29:19
welcome

and there is also wrong joining condition in ur query check it once by provided code.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-18 : 04:36:25
bklr, your rewrite negates the LEFT JOIN purpose.
SELECT		Count(UserInfo.user_id) AS CountOfuser_id, 
UserInfo.country
FROM UserInfo
LEFT JOIN (
SELECT ListingInfo.seller_id
FROM ListingInfo
INNER JOIN CheckoutInfo ON ListingInfo.item_id = CheckoutInfo.item_id
) AS x ON x.seller_id = UserInfo.user_id
GROUP BY UserInfo.country
See this example
DECLARE	@t1 TABLE
(i inT)

insert @t1 select 1 union all select 2

DECLARE @t2 TABLE
(j inT)

insert @t2 select 1

DECLARE @t3 TABLE
(k inT)

insert @t3 select 1 union all select 2 union all select 3

-- bklr
SELECT *
FROM @t1 as t1
LEFT JOIN @t2 AS t2 ON t2.j = t1.i
INNER JOIN @t3 AS t3 ON t3.k = t2.j

-- Peso
SELECT *
FROM @t1 as t1
LEFT JOIN (
SELECT *
FROM @t2 AS t2
INNER JOIN @t3 AS t3 ON t3.k = t2.j
) AS x ON x.j = t1.i



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-18 : 04:45:11
k thats fine and thanks peso
Go to Top of Page
   

- Advertisement -