Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2006, 02:41 PM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default UNION of Tables

Hi fellow programmers,

I have run into unfamiliar territory and could use some assistance. I am making a stock control system that has a table for entries(EntradasAlmacen) in to the warehouse and another table(NonSerials) for removals. I want to create a report that shows a particular product that user has selected between a time frame 1st/Jan/2006 to 1st/Feb/2006.

I am trying to tie the two table together inside an SQL statement as follows:

Code:
<% Set oRSbt=Server.CreateObject("ADODB.recordset")
strSQL = "SELECT ProductID, AlmacenID, Fecha, Quantity FROM EntradasAlmacen" _
       & " WHERE ProductID = '" & Request.Form("ddProduct") & "' ORDER BY Fecha" _
       & " UNION SELECT ProductID, AlmacenID, Fecha, Quantity FROM NonSerials" _
       & " WHERE ProductID = '" & Request.Form("ddProduct") & "' ORDER BY Fecha;"
oRSbt.open strSQL, "DSN=sanmarino" %>
When I loop through the entries I call a particular record as follows:

Code:
<%=oRSbt("Quantity")%>
However, I want this "Quantity" to be shown as either - or + depending if it is "EntradasAlmacen" or a "NonSerials", so that the report reflects that it is an Entry or Exit of stock.

I haven't incorporated the date aspect of the report yet as I am too busy trying to resolve this problem.

Any help will be greatly received.

Many thanks,

Paul
[email protected]
 
Old January 31st, 2006, 03:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Paul,

You can add an additional column to your resultset on the fly that determines the source table, like this:

SELECT Column1, Column2, 'EntradasAlmacen' AS QtyType FROM Table1
SELECT Column1, Column2, 'NonSerials' AS QtyType FROM Table2

Then in your ASP, you can use oRSbt("QtyType") to determine whether you're working with a EntradasAlmacen or a NonSerials.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 31st, 2006, 03:08 PM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Worked a treat... Many Many thanks

Paul





Similar Threads
Thread Thread Starter Forum Replies Last Post
Union Qry Corey Access 1 November 20th, 2006 06:21 AM
UNION query. rupen Access 3 April 28th, 2006 02:49 AM
Problem with UNION - Please Help brettk_1 SQL Server 2000 1 November 9th, 2004 08:08 AM
Binding multiple db tables to dataset (union) miguel.ossa C# 1 September 13th, 2004 02:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.