Tuesday, March 27, 2012

Easy SQL query question

Hi,
I have a table (PartNumberTbl) includes all the part number.
I want to add a part number 'ALL' in the following output so that user
can select "ALL" in the DropDownList control:
SELECT DISTINCT (PartNumber) FROM PartNumberTbl WHERE Customer =
@.Customer
I don't want to create a Part Number "ALL" for each customer.
How to do it without create a temp table?
Or is there a better way to handle this?
Thanks,
BenConsider adding it to the client code so that the general query without part
number 'ALL' can be reused by several other applications. If all
applications require this entry as one of the rows, then consider using the
UNION operator.
Anith|||You can handle this at the client side of your application,
or, you can issue the following SELECT statement.
(Suppose that PartNumber is a char column.)
SELECT PartNumber
FROM PartNumberTbl
WHERE Customer = @.Customer
UNION
SELECT 'ALL' as PartNumber
Martin C K Poon
Senior Analyst Programmer
====================================
"Ben" <wubin_98@.yahoo.com> ?
news:1150146922.304849.52960@.c74g2000cwc.googlegroups.com ?...
> Hi,
> I have a table (PartNumberTbl) includes all the part number.
> I want to add a part number 'ALL' in the following output so that user
> can select "ALL" in the DropDownList control:
> SELECT DISTINCT (PartNumber) FROM PartNumberTbl WHERE Customer =
> @.Customer
> I don't want to create a Part Number "ALL" for each customer.
> How to do it without create a temp table?
> Or is there a better way to handle this?
> Thanks,
> Ben
>

No comments:

Post a Comment