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 |
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.countryFROM 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_idGROUP BY UserInfo.countryHAVING (((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 5Incorrect syntax near the keyword 'ON'.Msg 102, Level 15, State 1, Line 8Incorrect syntax near 'Count'.Msg 102, Level 15, State 1, Line 9Incorrect 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.countryFROM UserInfo LEFT JOIN ListingInfo ON UserInfo.user_id = ListingInfo.seller_idINNER JOIN CheckoutInfo ON ListingInfo.item_id = CheckoutInfo.item_idGROUP BY UserInfo.countryHAVING (Count(UserInfo.user_id) > valuein 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 clausehow will be count value in userid value? |
|
|
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.countryFROM UserInfo LEFT JOIN (ListingInfo INNER JOIN CheckoutInfo ON ListingInfo.item_id = CheckoutInfo.item_id) on UserInfo.user_id = ListingInfo.seller_idLeft JOIN ListingDisputeInfoON ListingInfo.item_id = ListingDisputeInfo.item_idGROUP BY UserInfo.countryHAVING (((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 5Incorrect syntax near the keyword 'ON'.Msg 102, Level 15, State 1, Line 8Incorrect syntax near 'Count'.Msg 102, Level 15, State 1, Line 9Incorrect syntax near '='.Can someone let me know what's wrong with the script. thanks
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
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? |
|
|
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. |
|
|
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. |
|
|
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.countryFROM 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_idGROUP BY UserInfo.country See this exampleDECLARE @t1 TABLE (i inT)insert @t1 select 1 union all select 2DECLARE @t2 TABLE (j inT)insert @t2 select 1DECLARE @t3 TABLE (k inT)insert @t3 select 1 union all select 2 union all select 3-- bklrSELECT *FROM @t1 as t1LEFT JOIN @t2 AS t2 ON t2.j = t1.iINNER JOIN @t3 AS t3 ON t3.k = t2.j-- PesoSELECT *FROM @t1 as t1LEFT 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" |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-18 : 04:45:11
|
k thats fine and thanks peso |
|
|
|
|
|
|
|