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 |
|
Dana Rivlin
Starting Member
1 Post |
Posted - 2011-10-15 : 10:43:16
|
| SELECTcustomer,SUM(price) as expenses,COUNT(quarter) as VisitsPerQuarterFROM(selectcasewhen [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' endas segmentfrom dbo.SalesI get the message:Msg 102, Level 15, State 1, Line 15Incorrect 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 oneselect customer,SUM(price) as expenses,COUNT(quarter) as VisitsPerQuarterFROM(selectcasewhen [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' endas segmentfrom dbo.Sales) tempPlease mark answer as accepted if it helped you.Thanks,Jassi Singh |
 |
|
|
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 oneselect customer,SUM(price) as expenses,COUNT(quarter) as VisitsPerQuarterFROM(selectcasewhen [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' endas segmentfrom dbo.Sales) tempPlease mark answer as accepted if it helped you.Thanks,Jassi Singh
please test before posting.this wont even compile------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-15 : 12:47:12
|
it should beSELECTcustomer,SUM(price) as expenses,VisitsPerQuarterFROM(selectcasewhen [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' endas segment,customer,price,COUNT(1) OVER (PARTITION BY quarter) as VisitsPerQuarterfrom dbo.Sales)tGROUP 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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|