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
 what is my mistake???

Author  Topic 

Dana Rivlin
Starting Member

1 Post

Posted - 2011-10-15 : 10:43:16
SELECT

customer,
SUM(price) as expenses,
COUNT(quarter) as VisitsPerQuarter
FROM

(

select

case

when [expenses] > 370 and [visitsperquarter] > 3 then 'VIP'
when [expenses] > 370 and [visitsperquarter] IN (1,2) then 'gold'
when [expenses] >= 135 and [expenses] < 370 then 'silver'
when [expenses] < 135 then 'bronze' end
as segment
from dbo.Sales

I get the message:
Msg 102, Level 15, State 1, Line 15

Incorrect syntax near 'Sales'.

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-10-15 : 10:48:14
Please post your full query though i tried and check below one
select customer,
SUM(price) as expenses,
COUNT(quarter) as VisitsPerQuarter
FROM

(

select

case

when [expenses] > 370 and [visitsperquarter] > 3 then 'VIP'
when [expenses] > 370 and [visitsperquarter] IN (1,2) then 'gold'
when [expenses] >= 135 and [expenses] < 370 then 'silver'
when [expenses] < 135 then 'bronze' end
as segment
from dbo.Sales) temp


Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-15 : 12:43:33
quote:
Originally posted by jassi.singh

Please post your full query though i tried and check below one
select customer,
SUM(price) as expenses,
COUNT(quarter) as VisitsPerQuarter
FROM

(

select

case

when [expenses] > 370 and [visitsperquarter] > 3 then 'VIP'
when [expenses] > 370 and [visitsperquarter] IN (1,2) then 'gold'
when [expenses] >= 135 and [expenses] < 370 then 'silver'
when [expenses] < 135 then 'bronze' end
as segment
from dbo.Sales) temp


Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh


please test before posting.
this wont even compile

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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-15 : 12:47:12
it should be

SELECT
customer,
SUM(price) as expenses,
VisitsPerQuarter
FROM

(

select

case

when [expenses] > 370 and [visitsperquarter] > 3 then 'VIP'
when [expenses] > 370 and [visitsperquarter] IN (1,2) then 'gold'
when [expenses] >= 135 and [expenses] < 370 then 'silver'
when [expenses] < 135 then 'bronze' end
as segment,customer,price,
COUNT(1) OVER (PARTITION BY quarter) as VisitsPerQuarter
from dbo.Sales
)t
GROUP BY customer


I think Visits per quarter is wrong. As implied by name it should be number of visits of customer per quarter so I think it should be as above. Please confirm if thats what you want

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

Go to Top of Page
   

- Advertisement -