Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column Names as values query

Status
Not open for further replies.

Overmyhead2

Programmer
Jun 5, 2000
39
US
I need help. I've been reading everywhere. I've learned so far that this is not good programming practice to use col names like this.(forgive me). BUT.. just this once I need a SELECT query that will use Column Names to help put item descriptions into a report. I think I need dynamic SQL.
2 tables:
1. tblOrders has OrderID, OrderDate, SiteID, Category, Item1,Item2,Item3,Item4, so on to Item48
2. tblItems has ItemID(autonum),ItemName (Item1,Item2,Item3,..), Category, Description, Units..

When an Order is reviewed I SELECT Category, All Items
from tblOrders WHERE SessionID = SiteID AND #PickDate# = OrderDate. When displayed I want to show:
ITEM QTY
--------------------------------------------
(tblItems.Description&Units) (tblOrders.Item1)
(tblItems.Description&Units) (tblOrders.Item2)
(tblItems.Description&Units) (tblOrders.Item3)

ect... if Qty is not 0.
I have this so far
Code:
 <CFQUERY NAME="GetDetail" DATASOURCE="#DataSource#">
  DECLARE @Item1 int
    SELECT *
    FROM BREAD m, bread oi 
    WHERE oi.OrderID  = #URL.OrderID#
    AND oi.OrderID IN 
      (SELECT o.OrderID FROM Bread o
       WHERE o.SiteID = #SESSION.Auth.SiteID#)
I hope I didn't go overboard in explaining.
Apreciate any ideas.


Victoria
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top