RE: ORDER BY IIF(SoldUnits > 400, 0, 1), Description
- From: Junior <Junior@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Jan 2006 11:36:25 -0800
Works great, Vishal ! Thanks !
"Vishal Parkar" wrote:
> Check if example shown in following query works for you.
>
> create table #t(dsc varchar(50), units int)
>
> insert into #t
> select 'After dark' ,390 union all
> select 'All about eve',810 union all
> select 'Beginers' ,500 union all
> select 'Black Jack',300 union all
> select 'Cast a spell',220 union all
> select 'Charlie' ,410
>
> --Query.
>
> select * from #t
> order by case when units > 400 then 1 else 0 end desc, dsc asc
>
>
>
> "Junior" wrote:
>
> > Sure, Vishal... Thanks for the interest. Here it goes.
> >
> > Records ordered by description :
> >
> > 'After dark' (390 units sold)
> > 'All about eve' (810 units sold)
> > 'Beginers' (500 units sold)
> > 'Black Jack' (300 units sold)
> > 'Cast a spell' (220 units sold)
> > 'Charlie' (410 units sold)
> >
> > The way I want them to be (notice that the ones which sold more than 400
> > units are grouped alphabetically on top, and the rest above them, also
> > alphabetically ordered) :
> >
> > 'All about eve' (810 units sold)
> > 'Beginers' (500 units sold)
> > 'Charlie' (410 units sold)
> > 'After dark' (390 units sold)
> > 'Black Jack' (300 units sold)
> > 'Cast a spell' (220 units sold)
> >
> > Thanks again !
> >
> >
> >
> > "Vishal Parkar" wrote:
> >
> > > can you post sample data and expected result set. The statement "but want to
> > > put the 3 top sold items on top, all all others after them." is confusing. if
> > > you post sample data and expected result set then it wd be easy to understand.
> > >
> > > "Junior" wrote:
> > >
> > > > Hi everyone...
> > > >
> > > > I have to order a list of items in SQL 2000, but want to put the 3 top sold
> > > > items on top, all all others after them. I'd find out the break number easily
> > > > (400 in the example). It'd be two groups of description ordered items, as in :
> > > >
> > > > 'All about eve' (810 units sold)
> > > > 'Beginers' (500 units sold)
> > > > 'Charlie' (410 units sold)
> > > > 'After dark' (390 units sold)
> > > > 'Black Jack' (300 units sold)
> > > > 'Cast a spell' (220 units sold)
> > > > ...and so on.
> > > >
> > > > As IIF doesn't work in SQL Server, I tried to use 'ORDER BY (CASE SoldUnits
> > > > when SoldUnits >= 400 THEN 0 ELSE 1 END), Descricao', but an error occurs
> > > > (Incorrect syntax near '>'.). What is the solution for that ?
> > > >
> > > > Thanks very much !
> > > >
> > > > Junior
> > > >
.
- References:
- RE: ORDER BY IIF(SoldUnits > 400, 0, 1), Description
- From: Vishal Parkar
- RE: ORDER BY IIF(SoldUnits > 400, 0, 1), Description
- Prev by Date: Re: Multi Dimensional Cases in Time Series
- Next by Date: Re: creating more named calculations in a single data source view using amo
- Previous by thread: RE: ORDER BY IIF(SoldUnits > 400, 0, 1), Description
- Index(es):
Relevant Pages
|
|