Showing posts with label display. Show all posts
Showing posts with label display. Show all posts

Friday, March 30, 2012

Order By statement name begining with A

Hello

Can anybody tell me the correct MS SQL statement to display names: Where each name displayed is starting with a certain letter of the alphabet only. For example:

The list should show names starting with the letter A

(what must I change in my statement below)

SELECT LastN, FirstN, Tel
FROM People_DB
WHERE LastN = 'A'
ORDER BY LastN ASC

Last Name

    Adams,

    Andrews,

    Archer,

    Arrow

Thanks

Lynn

Use the LIKE operator with the % wildcard, like this:

SELECT LastN, FirstN, Tel
FROM People_DB
WHERE LastNLIKE 'A%'
ORDER BY LastN ASC

You can also use an underscore to match a single character. Check out the LIKE clause in BOL for all the options.

Don

|||

Hi Don

Thanks for the speedy reply and the information.

Lynn

Wednesday, March 28, 2012

ORDER BY Question

Item Quantity
I1 10
I2 7
I1 5
Assume that is the Data.
I want it ordered by Quantity FIRST and then show the same Item again
if it exists.
How can I display it in this way
Item Quantity
I1 10
I1 5
I2 7
P.S Please do not say "ORDER BY Item, Quanity DESC"I'll guess you want to order by max(Quantity) for the same item.
select
T.Item,
T.Quantity
from T
join (
select Item, max(Quantity) as maxQuantity
from T
group by Item
) as Tmax
on Tmax.Item = T.Item
order by maxQuantity desc
[Not tested, but I hope you get the idea]
Steve Kass
Drew University
rythm wrote:

> Item Quantity
>I1 10
>I2 7
>I1 5
>Assume that is the Data.
>I want it ordered by Quantity FIRST and then show the same Item again
>if it exists.
>How can I display it in this way
>Item Quantity
>I1 10
>I1 5
>I2 7
>P.S Please do not say "ORDER BY Item, Quanity DESC"
>|||Thanks that did work.
After looking at it, it seems so simple.
I couldn't even think of performing it in that ordersql