Saturday, February 25, 2012

pass a value

is it possible to do:
(A)
declare @.numberofitems Int
@.numberofitems = select max(itemorder)
from store, department, etc.

and pass the @.numberofitems to a #tempStore table, like:
(B)
(store, department, @.numberofitems,...)

I got itemorder but not the number of items in each department
Alex

--
Sent by 3 from yahoo part from com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/newHi

You don;t give enough detail to produce an exact query. Please post DDL,
example data (as insert statements) and expected output if you require a
more precise answer.

At a guess something like:

SELECT S.Store, D.Department, max(I.itemorder) as NumberOfItems
from store S JOIN department D ON S.StoreId = D.StoreId
JOIN ItemsOrders I On I.DeptId = D.DeptId
GROUP BY S.Store, D.Department

or

SELECT S.Store, D.Department, ( SELECT max(I.itemorder) FROM ItemsOrders I
WHERE I.DeptId = D.DeptId AND S.StoreId = I.StoreId ) as NumberOfItems
FROM store S JOIN department D ON S.StoreId = D.StoreId

John

etc"alexqa2003@.yahoo.com" <u128845214@.spawnkill.ip-mobilphone.net> wrote in
message news:l.1062471242.1626678466@.host-66-81-78-52.rev.o1.com...
> is it possible to do:
> (A)
> declare @.numberofitems Int
> @.numberofitems = select max(itemorder)
> from store, department, etc.
> and pass the @.numberofitems to a #tempStore table, like:
> (B)
> (store, department, @.numberofitems,...)
> I got itemorder but not the number of items in each department
> Alex
>
>
> --
> Sent by 3 from yahoo part from com
> This is a spam protected message. Please answer with reference header.
> Posted via http://www.usenet-replayer.com/cgi/content/new|||u128845214@.spawnkill.ip-mobilphone.net (alexqa2003@.yahoo.com) wrote in message news:<l.1062471242.1626678466@.host-66-81-78-52.rev.o1.com>...
> is it possible to do:
> (A)
> declare @.numberofitems Int
> @.numberofitems = select max(itemorder)
> from store, department, etc.
> and pass the @.numberofitems to a #tempStore table, like:
> (B)
> (store, department, @.numberofitems,...)
> I got itemorder but not the number of items in each department
> Alex

It's not really clear from your post what you're trying to do, but it
may be something like this:

insert into #tempStore
(store, department, numberofitems)
select store, department, max(itemorder)
from orders
group by store, department

Or maybe this:

insert into #tempStore
(store, department, numberofitems)
select store, department, count(itemorder)
from orders
group by store, department

If this doesn't help, then it would be good if you can post your DDL
(CREATE TABLE statements), along with some sample data and the
expected output.

Simon

No comments:

Post a Comment