473,804 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Query Quandry

Hi All

Sorry for the spare info. It wasn't because I didn't want to display it. I
just didn't know how to get the data that you needed. I think I've got it
now so please note the following:

1) The DB is SQL 6.5.

2) My DDL for the tables in question:

/****** Object: Table [dbo].[SALESCENTRES] Script Date: 17/04/04
21:27:00 ******/
CREATE TABLE [dbo].[SALESCENTRES] (
[SALESCENTREID] [T_SALESCENTRESD OMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[COMMENT] [varchar] (255) NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[SPOOLEDINVOICEL INES] Script Date: 17/04/04
21:27:05 ******/
CREATE TABLE [dbo].[SPOOLEDINVOICEL INES] (
[SPOOLEDINVOICEI D] [T_SpooledInvoic esDomain] NOT NULL ,
[LINE] [int] NOT NULL ,
[STOCKID] [T_STOCKDOMAIN] NULL ,
[DESCRIPTION] [varchar] (255) NULL ,
[FREETEXTLINE] [tinyint] NULL ,
[UNITOFSALE] [varchar] (20) NULL ,
[QUANTITY] [float] NULL ,
[COSTPRICE] [float] NULL ,
[SELLINGPRICE] [float] NULL ,
[PRICELEVELID] [T_PRICELEVELSDO MAIN] NULL ,
[DISCOUNTPERCENT] [float] NULL ,
[NOMINALACCOUNTI D] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[VATRATEID] [T_VATRATESDOMAI N] NULL ,
[VATPERCENT] [float] NULL ,
[VATAMOUNT] [money] NULL ,
[LINEPRICE] [money] NULL ,
[TimeStamp] [timestamp] NULL
)
GO

/****** Object: Table [dbo].[SPOOLEDINVOICES] Script Date: 17/04/04
21:27:09 ******/
CREATE TABLE [dbo].[SPOOLEDINVOICES] (
[SPOOLEDINVOICEI D] [T_SpooledInvoic esDomain] IDENTITY (1, 1) NOT NULL ,
[INVOICETYPE] [smallint] NOT NULL ,
[PEOPLEID] [T_PEOPLEDOMAIN] NOT NULL ,
[ACCOUNTID] [T_ACCOUNTSDOMAI N] NOT NULL ,
[ORDERNUMBER] [varchar] (40) NULL ,
[INVOICENUMBER] [int] NULL ,
[PREFIX] [varchar] (10) NULL ,
[SUFFIX] [varchar] (10) NULL ,
[INVOICEDATE] [datetime] NULL ,
[DATEDUE] [datetime] NULL ,
[PLACEDBY] [varchar] (40) NULL ,
[TELEPHONE] [varchar] (40) NULL ,
[LANGUAGEID] [T_LANGUAGESDOMA IN] NULL ,
[AGENTID] [T_AGENTSDOMAIN] NULL ,
[CUSTOMERTYPEID] [T_CUSTOMERTYPES DOMAIN] NULL ,
[SALESCENTREID] [T_SALESCENTRESD OMAIN] NULL ,
[DEPARTMENTID] [T_DEPARTMENTSDO MAIN] NULL ,
[WAREHOUSEID] [T_WAREHOUSESDOM AIN] NULL ,
[TRADINGTYPE] [smallint] NULL ,
[TRADINGDAYOFMON TH] [smallint] NULL ,
[TRADINGDAYSTIME] [smallint] NULL ,
[DISCOUNTPERCENT] [float] NULL ,
[SETTLEMENTPERCE NT] [float] NULL ,
[PayNow] [tinyint] NULL ,
[AmountTendered] [money] NULL ,
[Balance] [money] NULL ,
[DiscountTaken] [money] NULL ,
[MethodOfPayment] [varchar] (40) NULL ,
[PayReference] [varchar] (40) NULL ,
[Authorisation] [varchar] (40) NULL ,
[PRICELEVELID] [T_PRICELEVELSDO MAIN] NULL ,
[TOTALNETT] [money] NULL ,
[TOTALVAT] [money] NULL ,
[TOTALDISCOUNT] [money] NULL ,
[TRADINGTERMS] [varchar] (40) NULL ,
[INVOICEMESSAGES] [varchar] (255) NULL ,
[COMMENT] [varchar] (255) NULL ,
[PLRate] [float] NULL ,
[BSRate] [float] NULL ,
[INVOICECONTACTI D] [T_CONTACTDETAIL SDOMAIN] NULL ,
[DELIVERYCONTACT ID] [T_CONTACTDETAIL SDOMAIN] NULL ,
[ORDERCONTACTID] [T_CONTACTDETAIL SDOMAIN] NULL ,
[UserID] [T_UsersDomain] NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[STOCK] Script Date: 17/04/04 21:27:13
******/
CREATE TABLE [dbo].[STOCK] (
[STOCKID] [T_STOCKDOMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[PICTURE] [varchar] (40) NULL ,
[WEIGHT] [float] NULL ,
[VOLUME] [float] NULL ,
[BARCODE] [smallint] NULL ,
[NumberOfPriceBr eaks] [smallint] NOT NULL ,
[STOCKCATEGORYID] [T_STOCKCATEGORI ESDOMAIN] NULL ,
[SALESNOMINALID] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[PURCHASENOMINAL ID] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[SELLINGCOMMENT] [varchar] (255) NULL ,
[INCLUDESELLINGC OMMENT] [tinyint] NULL ,
[DISPLAYSELLINGC OMMENT] [tinyint] NULL ,
[COSTCOMMENT] [varchar] (255) NULL ,
[DISPLAYCOSTCOMM ENT] [tinyint] NULL ,
[PRODUCTTRACKING] [smallint] NULL ,
[ITEMTYPE] [smallint] NULL ,
[VALUATIONPRICE] [float] NOT NULL ,
[INCLUDEINCUSTOM ERSTURNOVER] [tinyint] NULL ,
[INCLUDEINAGENTS TURNOVER] [tinyint] NULL ,
[SUPERCEDED] [tinyint] NULL ,
[SUPERCEDEDBY] [T_STOCKDOMAIN] NULL ,
[SUPPLIERID] [T_PEOPLEDOMAIN] NULL ,
[SUPPLIERSTOCKID] [varchar] (40) NULL ,
[SUPPLIERCOMMENT] [varchar] (255) NULL ,
[NEXTSERIALNUMBE R] [int] NULL ,
[SERIALNUMBERLEN GTH] [smallint] NULL ,
[SERIALNUMBERPRE FIX] [varchar] (10) NULL ,
[SERIALNUMBERSUF FIX] [varchar] (10) NULL ,
[SERIALNUMBERPRE FIXLENGTH] [smallint] NULL ,
[SERIALNUMBERSUF FIXLENGTH] [smallint] NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[STOCKCATEGORIES] Script Date: 17/04/04
21:27:16 ******/
CREATE TABLE [dbo].[STOCKCATEGORIES] (
[STOCKCATEGORYID] [T_STOCKCATEGORI ESDOMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[COMMENT] [varchar] (255) NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

ALTER TABLE [dbo].[SALESCENTRES] WITH NOCHECK ADD
CONSTRAINT [pk_salescentres] PRIMARY KEY CLUSTERED
(
[SALESCENTREID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SPOOLEDINVOICEL INES] WITH NOCHECK ADD
CONSTRAINT [pk_spooledinvoi celines] PRIMARY KEY CLUSTERED
(
[SPOOLEDINVOICEI D],
[LINE]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SPOOLEDINVOICES] WITH NOCHECK ADD
CONSTRAINT [pk_spooledinvoi ces] PRIMARY KEY CLUSTERED
(
[SPOOLEDINVOICEI D]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[STOCK] WITH NOCHECK ADD
CONSTRAINT [pk_stock] PRIMARY KEY CLUSTERED
(
[STOCKID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[STOCKCATEGORIES] WITH NOCHECK ADD
CONSTRAINT [pk_stockcategor ies] PRIMARY KEY CLUSTERED
(
[STOCKCATEGORYID]
) ON [PRIMARY]
GO

I know there appears to be a lot of data here, but believe me I am only
wanting to use a small porttion of it.

3) My current query is as follows:

SELECT SALESCENTRES.NA ME, STOCKCATEGORIES .NAME,
SPOOLEDINVOICEL INES.QUANTITY, SPOOLEDINVOICES .INVOICEDATE
FROM SALESCENTRES, SPOOLEDINVOICEL INES, SPOOLEDINVOICES , STOCK,
STOCKCATEGORIES
WHERE SPOOLEDINVOICEL INES.SPOOLEDINV OICEID =
SPOOLEDINVOICES .SPOOLEDINVOICE ID AND STOCK.STOCKID =
SPOOLEDINVOICEL INES.STOCKID AND STOCKCATEGORIES .STOCKCATEGORYI D =
STOCK.STOCKCATE GORYID AND SALESCENTRES.SA LESCENTREID =
SPOOLEDINVOICES .SALESCENTREID AND ((SPOOLEDINVOIC ES.INVOICEDATE> {ts
'2004-04-01 00:00:00'}) AND (SPOOLEDINVOICE S.INVOICEDATE<{ ts '2004-08-01
00:00:00'}))

Where the 2 date values would actually be variable data that the user had
entered.

As I said before when I put the SALESCENTRES.NA ME field in the left hand
portion of my Pivot table, the STOCKCATEGORIES .NAME in the top portion of my
Pivot table and the SPOOLEDINVOICEL INES.QUANTITY in the data/middle section
of the pivot table I get the kind of result I want (see results below), but
it only retrieves data where I have values for the SALESCENTRES.NA ME and the
STOCKCATEGORIES .NAME. What I want is to show all of the SALESCENTRES.NA ME
fields (down the left) and all of the STOCKCATEGORIES .NAME fields (across
the top) and if there isn't a SPOOLEDINVOICEL INES.QUANTITY value for a
particular cross section then it simply shows a zero. My examples below
should show it better.

My current pivot table shows:

StockCat1 StockCat4
SalesC1 25 3
SalesC2 4 6
Grand Total 29 9

But I want to show:

StockCat1 StockCat2 StockCat3
StockCat4 (etc...)
SalesC1 25 0 0
3
SalesC2 4 0 0
6
SalesC3 0 0 0
0
etc...
Grand Total 29 0 0
9

I'm sure it's down to joins, but I'm at a loss on how to do it.

I hope the above helps and appreciate any time you can give to it.

Rgds

Laphan

Jul 20 '05 #1
2 1415

"Laphan" <ne**@DoNotEmai lMe.co.uk> wrote in message
news:40******** @127.0.0.1...
Hi All

Sorry for the spare info. It wasn't because I didn't want to display it. I just didn't know how to get the data that you needed. I think I've got it
now so please note the following:

1) The DB is SQL 6.5.

2) My DDL for the tables in question:

/****** Object: Table [dbo].[SALESCENTRES] Script Date: 17/04/04
21:27:00 ******/
CREATE TABLE [dbo].[SALESCENTRES] (
[SALESCENTREID] [T_SALESCENTRESD OMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[COMMENT] [varchar] (255) NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[SPOOLEDINVOICEL INES] Script Date: 17/04/04 21:27:05 ******/
CREATE TABLE [dbo].[SPOOLEDINVOICEL INES] (
[SPOOLEDINVOICEI D] [T_SpooledInvoic esDomain] NOT NULL ,
[LINE] [int] NOT NULL ,
[STOCKID] [T_STOCKDOMAIN] NULL ,
[DESCRIPTION] [varchar] (255) NULL ,
[FREETEXTLINE] [tinyint] NULL ,
[UNITOFSALE] [varchar] (20) NULL ,
[QUANTITY] [float] NULL ,
[COSTPRICE] [float] NULL ,
[SELLINGPRICE] [float] NULL ,
[PRICELEVELID] [T_PRICELEVELSDO MAIN] NULL ,
[DISCOUNTPERCENT] [float] NULL ,
[NOMINALACCOUNTI D] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[VATRATEID] [T_VATRATESDOMAI N] NULL ,
[VATPERCENT] [float] NULL ,
[VATAMOUNT] [money] NULL ,
[LINEPRICE] [money] NULL ,
[TimeStamp] [timestamp] NULL
)
GO

/****** Object: Table [dbo].[SPOOLEDINVOICES] Script Date: 17/04/04
21:27:09 ******/
CREATE TABLE [dbo].[SPOOLEDINVOICES] (
[SPOOLEDINVOICEI D] [T_SpooledInvoic esDomain] IDENTITY (1, 1) NOT NULL ,
[INVOICETYPE] [smallint] NOT NULL ,
[PEOPLEID] [T_PEOPLEDOMAIN] NOT NULL ,
[ACCOUNTID] [T_ACCOUNTSDOMAI N] NOT NULL ,
[ORDERNUMBER] [varchar] (40) NULL ,
[INVOICENUMBER] [int] NULL ,
[PREFIX] [varchar] (10) NULL ,
[SUFFIX] [varchar] (10) NULL ,
[INVOICEDATE] [datetime] NULL ,
[DATEDUE] [datetime] NULL ,
[PLACEDBY] [varchar] (40) NULL ,
[TELEPHONE] [varchar] (40) NULL ,
[LANGUAGEID] [T_LANGUAGESDOMA IN] NULL ,
[AGENTID] [T_AGENTSDOMAIN] NULL ,
[CUSTOMERTYPEID] [T_CUSTOMERTYPES DOMAIN] NULL ,
[SALESCENTREID] [T_SALESCENTRESD OMAIN] NULL ,
[DEPARTMENTID] [T_DEPARTMENTSDO MAIN] NULL ,
[WAREHOUSEID] [T_WAREHOUSESDOM AIN] NULL ,
[TRADINGTYPE] [smallint] NULL ,
[TRADINGDAYOFMON TH] [smallint] NULL ,
[TRADINGDAYSTIME] [smallint] NULL ,
[DISCOUNTPERCENT] [float] NULL ,
[SETTLEMENTPERCE NT] [float] NULL ,
[PayNow] [tinyint] NULL ,
[AmountTendered] [money] NULL ,
[Balance] [money] NULL ,
[DiscountTaken] [money] NULL ,
[MethodOfPayment] [varchar] (40) NULL ,
[PayReference] [varchar] (40) NULL ,
[Authorisation] [varchar] (40) NULL ,
[PRICELEVELID] [T_PRICELEVELSDO MAIN] NULL ,
[TOTALNETT] [money] NULL ,
[TOTALVAT] [money] NULL ,
[TOTALDISCOUNT] [money] NULL ,
[TRADINGTERMS] [varchar] (40) NULL ,
[INVOICEMESSAGES] [varchar] (255) NULL ,
[COMMENT] [varchar] (255) NULL ,
[PLRate] [float] NULL ,
[BSRate] [float] NULL ,
[INVOICECONTACTI D] [T_CONTACTDETAIL SDOMAIN] NULL ,
[DELIVERYCONTACT ID] [T_CONTACTDETAIL SDOMAIN] NULL ,
[ORDERCONTACTID] [T_CONTACTDETAIL SDOMAIN] NULL ,
[UserID] [T_UsersDomain] NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[STOCK] Script Date: 17/04/04 21:27:13
******/
CREATE TABLE [dbo].[STOCK] (
[STOCKID] [T_STOCKDOMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[PICTURE] [varchar] (40) NULL ,
[WEIGHT] [float] NULL ,
[VOLUME] [float] NULL ,
[BARCODE] [smallint] NULL ,
[NumberOfPriceBr eaks] [smallint] NOT NULL ,
[STOCKCATEGORYID] [T_STOCKCATEGORI ESDOMAIN] NULL ,
[SALESNOMINALID] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[PURCHASENOMINAL ID] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[SELLINGCOMMENT] [varchar] (255) NULL ,
[INCLUDESELLINGC OMMENT] [tinyint] NULL ,
[DISPLAYSELLINGC OMMENT] [tinyint] NULL ,
[COSTCOMMENT] [varchar] (255) NULL ,
[DISPLAYCOSTCOMM ENT] [tinyint] NULL ,
[PRODUCTTRACKING] [smallint] NULL ,
[ITEMTYPE] [smallint] NULL ,
[VALUATIONPRICE] [float] NOT NULL ,
[INCLUDEINCUSTOM ERSTURNOVER] [tinyint] NULL ,
[INCLUDEINAGENTS TURNOVER] [tinyint] NULL ,
[SUPERCEDED] [tinyint] NULL ,
[SUPERCEDEDBY] [T_STOCKDOMAIN] NULL ,
[SUPPLIERID] [T_PEOPLEDOMAIN] NULL ,
[SUPPLIERSTOCKID] [varchar] (40) NULL ,
[SUPPLIERCOMMENT] [varchar] (255) NULL ,
[NEXTSERIALNUMBE R] [int] NULL ,
[SERIALNUMBERLEN GTH] [smallint] NULL ,
[SERIALNUMBERPRE FIX] [varchar] (10) NULL ,
[SERIALNUMBERSUF FIX] [varchar] (10) NULL ,
[SERIALNUMBERPRE FIXLENGTH] [smallint] NULL ,
[SERIALNUMBERSUF FIXLENGTH] [smallint] NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[STOCKCATEGORIES] Script Date: 17/04/04
21:27:16 ******/
CREATE TABLE [dbo].[STOCKCATEGORIES] (
[STOCKCATEGORYID] [T_STOCKCATEGORI ESDOMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[COMMENT] [varchar] (255) NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

ALTER TABLE [dbo].[SALESCENTRES] WITH NOCHECK ADD
CONSTRAINT [pk_salescentres] PRIMARY KEY CLUSTERED
(
[SALESCENTREID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SPOOLEDINVOICEL INES] WITH NOCHECK ADD
CONSTRAINT [pk_spooledinvoi celines] PRIMARY KEY CLUSTERED
(
[SPOOLEDINVOICEI D],
[LINE]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SPOOLEDINVOICES] WITH NOCHECK ADD
CONSTRAINT [pk_spooledinvoi ces] PRIMARY KEY CLUSTERED
(
[SPOOLEDINVOICEI D]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[STOCK] WITH NOCHECK ADD
CONSTRAINT [pk_stock] PRIMARY KEY CLUSTERED
(
[STOCKID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[STOCKCATEGORIES] WITH NOCHECK ADD
CONSTRAINT [pk_stockcategor ies] PRIMARY KEY CLUSTERED
(
[STOCKCATEGORYID]
) ON [PRIMARY]
GO

I know there appears to be a lot of data here, but believe me I am only
wanting to use a small porttion of it.

3) My current query is as follows:

SELECT SALESCENTRES.NA ME, STOCKCATEGORIES .NAME,
SPOOLEDINVOICEL INES.QUANTITY, SPOOLEDINVOICES .INVOICEDATE
FROM SALESCENTRES, SPOOLEDINVOICEL INES, SPOOLEDINVOICES , STOCK,
STOCKCATEGORIES
WHERE SPOOLEDINVOICEL INES.SPOOLEDINV OICEID =
SPOOLEDINVOICES .SPOOLEDINVOICE ID AND STOCK.STOCKID =
SPOOLEDINVOICEL INES.STOCKID AND STOCKCATEGORIES .STOCKCATEGORYI D =
STOCK.STOCKCATE GORYID AND SALESCENTRES.SA LESCENTREID =
SPOOLEDINVOICES .SALESCENTREID AND ((SPOOLEDINVOIC ES.INVOICEDATE> {ts
'2004-04-01 00:00:00'}) AND (SPOOLEDINVOICE S.INVOICEDATE<{ ts '2004-08-01
00:00:00'}))

Where the 2 date values would actually be variable data that the user had
entered.

As I said before when I put the SALESCENTRES.NA ME field in the left hand
portion of my Pivot table, the STOCKCATEGORIES .NAME in the top portion of my Pivot table and the SPOOLEDINVOICEL INES.QUANTITY in the data/middle section of the pivot table I get the kind of result I want (see results below), but it only retrieves data where I have values for the SALESCENTRES.NA ME and the STOCKCATEGORIES .NAME. What I want is to show all of the SALESCENTRES.NA ME
fields (down the left) and all of the STOCKCATEGORIES .NAME fields (across
the top) and if there isn't a SPOOLEDINVOICEL INES.QUANTITY value for a
particular cross section then it simply shows a zero. My examples below
should show it better.

My current pivot table shows:

StockCat1 StockCat4
SalesC1 25 3
SalesC2 4 6
Grand Total 29 9

But I want to show:

StockCat1 StockCat2 StockCat3
StockCat4 (etc...)
SalesC1 25 0 0
3
SalesC2 4 0 0
6
SalesC3 0 0 0
0
etc...
Grand Total 29 0 0
9

I'm sure it's down to joins, but I'm at a loss on how to do it.

I hope the above helps and appreciate any time you can give to it.

Rgds

Laphan

Jul 20 '05 #2
Hi

Your syntax is not ANSI format. What you require is an outer join. This is
described with examples in Books Online:

mk:@MSITStore:C :\Program%20Fil es\Microsoft%20 SQL%20Server\80 \Tools\Books\ac d
ata.chm::/ac_8_qd_09_0zqr .htm

It is also useful to include your example data as insert statements along
with all the DDL.

e.g

SELECT C.NAME, T.NAME,
SPOOLEDINVOICEL INES.QUANTITY, I.INVOICEDATE
FROM SALESCENTRES C LEFT JOIN SPOOLEDINVOICES I ON
C.SALESCENTREID = I.SALESCENTREID
JOIN SPOOLEDINVOICEL INES L ON L.SPOOLEDINVOIC EID = I.SPOOLEDINVOIC EID
JOIN STOCK S ON S.STOCKID = L.STOCKID
STOCKCATEGORIES T ON T.STOCKCATEGORY ID = S.STOCKCATEGORY ID
WHERE I.INVOICEDATE > '2004-04-01 00:00:00'
AND I.INVOICEDATE < '2004-08-01 00:00:00'

John

"Laphan" <ne**@DoNotEmai lMe.co.uk> wrote in message
news:40******** @127.0.0.1...
Hi All

Sorry for the spare info. It wasn't because I didn't want to display it. I just didn't know how to get the data that you needed. I think I've got it
now so please note the following:

1) The DB is SQL 6.5.

2) My DDL for the tables in question:

/****** Object: Table [dbo].[SALESCENTRES] Script Date: 17/04/04
21:27:00 ******/
CREATE TABLE [dbo].[SALESCENTRES] (
[SALESCENTREID] [T_SALESCENTRESD OMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[COMMENT] [varchar] (255) NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[SPOOLEDINVOICEL INES] Script Date: 17/04/04 21:27:05 ******/
CREATE TABLE [dbo].[SPOOLEDINVOICEL INES] (
[SPOOLEDINVOICEI D] [T_SpooledInvoic esDomain] NOT NULL ,
[LINE] [int] NOT NULL ,
[STOCKID] [T_STOCKDOMAIN] NULL ,
[DESCRIPTION] [varchar] (255) NULL ,
[FREETEXTLINE] [tinyint] NULL ,
[UNITOFSALE] [varchar] (20) NULL ,
[QUANTITY] [float] NULL ,
[COSTPRICE] [float] NULL ,
[SELLINGPRICE] [float] NULL ,
[PRICELEVELID] [T_PRICELEVELSDO MAIN] NULL ,
[DISCOUNTPERCENT] [float] NULL ,
[NOMINALACCOUNTI D] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[VATRATEID] [T_VATRATESDOMAI N] NULL ,
[VATPERCENT] [float] NULL ,
[VATAMOUNT] [money] NULL ,
[LINEPRICE] [money] NULL ,
[TimeStamp] [timestamp] NULL
)
GO

/****** Object: Table [dbo].[SPOOLEDINVOICES] Script Date: 17/04/04
21:27:09 ******/
CREATE TABLE [dbo].[SPOOLEDINVOICES] (
[SPOOLEDINVOICEI D] [T_SpooledInvoic esDomain] IDENTITY (1, 1) NOT NULL ,
[INVOICETYPE] [smallint] NOT NULL ,
[PEOPLEID] [T_PEOPLEDOMAIN] NOT NULL ,
[ACCOUNTID] [T_ACCOUNTSDOMAI N] NOT NULL ,
[ORDERNUMBER] [varchar] (40) NULL ,
[INVOICENUMBER] [int] NULL ,
[PREFIX] [varchar] (10) NULL ,
[SUFFIX] [varchar] (10) NULL ,
[INVOICEDATE] [datetime] NULL ,
[DATEDUE] [datetime] NULL ,
[PLACEDBY] [varchar] (40) NULL ,
[TELEPHONE] [varchar] (40) NULL ,
[LANGUAGEID] [T_LANGUAGESDOMA IN] NULL ,
[AGENTID] [T_AGENTSDOMAIN] NULL ,
[CUSTOMERTYPEID] [T_CUSTOMERTYPES DOMAIN] NULL ,
[SALESCENTREID] [T_SALESCENTRESD OMAIN] NULL ,
[DEPARTMENTID] [T_DEPARTMENTSDO MAIN] NULL ,
[WAREHOUSEID] [T_WAREHOUSESDOM AIN] NULL ,
[TRADINGTYPE] [smallint] NULL ,
[TRADINGDAYOFMON TH] [smallint] NULL ,
[TRADINGDAYSTIME] [smallint] NULL ,
[DISCOUNTPERCENT] [float] NULL ,
[SETTLEMENTPERCE NT] [float] NULL ,
[PayNow] [tinyint] NULL ,
[AmountTendered] [money] NULL ,
[Balance] [money] NULL ,
[DiscountTaken] [money] NULL ,
[MethodOfPayment] [varchar] (40) NULL ,
[PayReference] [varchar] (40) NULL ,
[Authorisation] [varchar] (40) NULL ,
[PRICELEVELID] [T_PRICELEVELSDO MAIN] NULL ,
[TOTALNETT] [money] NULL ,
[TOTALVAT] [money] NULL ,
[TOTALDISCOUNT] [money] NULL ,
[TRADINGTERMS] [varchar] (40) NULL ,
[INVOICEMESSAGES] [varchar] (255) NULL ,
[COMMENT] [varchar] (255) NULL ,
[PLRate] [float] NULL ,
[BSRate] [float] NULL ,
[INVOICECONTACTI D] [T_CONTACTDETAIL SDOMAIN] NULL ,
[DELIVERYCONTACT ID] [T_CONTACTDETAIL SDOMAIN] NULL ,
[ORDERCONTACTID] [T_CONTACTDETAIL SDOMAIN] NULL ,
[UserID] [T_UsersDomain] NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[STOCK] Script Date: 17/04/04 21:27:13
******/
CREATE TABLE [dbo].[STOCK] (
[STOCKID] [T_STOCKDOMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[PICTURE] [varchar] (40) NULL ,
[WEIGHT] [float] NULL ,
[VOLUME] [float] NULL ,
[BARCODE] [smallint] NULL ,
[NumberOfPriceBr eaks] [smallint] NOT NULL ,
[STOCKCATEGORYID] [T_STOCKCATEGORI ESDOMAIN] NULL ,
[SALESNOMINALID] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[PURCHASENOMINAL ID] [T_NOMINALACCOUN TSDOMAIN] NULL ,
[SELLINGCOMMENT] [varchar] (255) NULL ,
[INCLUDESELLINGC OMMENT] [tinyint] NULL ,
[DISPLAYSELLINGC OMMENT] [tinyint] NULL ,
[COSTCOMMENT] [varchar] (255) NULL ,
[DISPLAYCOSTCOMM ENT] [tinyint] NULL ,
[PRODUCTTRACKING] [smallint] NULL ,
[ITEMTYPE] [smallint] NULL ,
[VALUATIONPRICE] [float] NOT NULL ,
[INCLUDEINCUSTOM ERSTURNOVER] [tinyint] NULL ,
[INCLUDEINAGENTS TURNOVER] [tinyint] NULL ,
[SUPERCEDED] [tinyint] NULL ,
[SUPERCEDEDBY] [T_STOCKDOMAIN] NULL ,
[SUPPLIERID] [T_PEOPLEDOMAIN] NULL ,
[SUPPLIERSTOCKID] [varchar] (40) NULL ,
[SUPPLIERCOMMENT] [varchar] (255) NULL ,
[NEXTSERIALNUMBE R] [int] NULL ,
[SERIALNUMBERLEN GTH] [smallint] NULL ,
[SERIALNUMBERPRE FIX] [varchar] (10) NULL ,
[SERIALNUMBERSUF FIX] [varchar] (10) NULL ,
[SERIALNUMBERPRE FIXLENGTH] [smallint] NULL ,
[SERIALNUMBERSUF FIXLENGTH] [smallint] NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

/****** Object: Table [dbo].[STOCKCATEGORIES] Script Date: 17/04/04
21:27:16 ******/
CREATE TABLE [dbo].[STOCKCATEGORIES] (
[STOCKCATEGORYID] [T_STOCKCATEGORI ESDOMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[COMMENT] [varchar] (255) NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

ALTER TABLE [dbo].[SALESCENTRES] WITH NOCHECK ADD
CONSTRAINT [pk_salescentres] PRIMARY KEY CLUSTERED
(
[SALESCENTREID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SPOOLEDINVOICEL INES] WITH NOCHECK ADD
CONSTRAINT [pk_spooledinvoi celines] PRIMARY KEY CLUSTERED
(
[SPOOLEDINVOICEI D],
[LINE]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SPOOLEDINVOICES] WITH NOCHECK ADD
CONSTRAINT [pk_spooledinvoi ces] PRIMARY KEY CLUSTERED
(
[SPOOLEDINVOICEI D]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[STOCK] WITH NOCHECK ADD
CONSTRAINT [pk_stock] PRIMARY KEY CLUSTERED
(
[STOCKID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[STOCKCATEGORIES] WITH NOCHECK ADD
CONSTRAINT [pk_stockcategor ies] PRIMARY KEY CLUSTERED
(
[STOCKCATEGORYID]
) ON [PRIMARY]
GO

I know there appears to be a lot of data here, but believe me I am only
wanting to use a small porttion of it.

3) My current query is as follows:

SELECT SALESCENTRES.NA ME, STOCKCATEGORIES .NAME,
SPOOLEDINVOICEL INES.QUANTITY, SPOOLEDINVOICES .INVOICEDATE
FROM SALESCENTRES, SPOOLEDINVOICEL INES, SPOOLEDINVOICES , STOCK,
STOCKCATEGORIES
WHERE SPOOLEDINVOICEL INES.SPOOLEDINV OICEID =
SPOOLEDINVOICES .SPOOLEDINVOICE ID AND STOCK.STOCKID =
SPOOLEDINVOICEL INES.STOCKID AND STOCKCATEGORIES .STOCKCATEGORYI D =
STOCK.STOCKCATE GORYID AND SALESCENTRES.SA LESCENTREID =
SPOOLEDINVOICES .SALESCENTREID AND ((SPOOLEDINVOIC ES.INVOICEDATE> {ts
'2004-04-01 00:00:00'}) AND (SPOOLEDINVOICE S.INVOICEDATE<{ ts '2004-08-01
00:00:00'}))

Where the 2 date values would actually be variable data that the user had
entered.

As I said before when I put the SALESCENTRES.NA ME field in the left hand
portion of my Pivot table, the STOCKCATEGORIES .NAME in the top portion of my Pivot table and the SPOOLEDINVOICEL INES.QUANTITY in the data/middle section of the pivot table I get the kind of result I want (see results below), but it only retrieves data where I have values for the SALESCENTRES.NA ME and the STOCKCATEGORIES .NAME. What I want is to show all of the SALESCENTRES.NA ME
fields (down the left) and all of the STOCKCATEGORIES .NAME fields (across
the top) and if there isn't a SPOOLEDINVOICEL INES.QUANTITY value for a
particular cross section then it simply shows a zero. My examples below
should show it better.

My current pivot table shows:

StockCat1 StockCat4
SalesC1 25 3
SalesC2 4 6
Grand Total 29 9

But I want to show:

StockCat1 StockCat2 StockCat3
StockCat4 (etc...)
SalesC1 25 0 0
3
SalesC2 4 0 0
6
SalesC3 0 0 0
0
etc...
Grand Total 29 0 0
9

I'm sure it's down to joins, but I'm at a loss on how to do it.

I hope the above helps and appreciate any time you can give to it.

Rgds

Laphan

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3436
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the new values are updated in all corresponding tables (the function of the pages in question). However, on the page that does the DB update, I also want to do some checks on the data before performing the update. Now, the problem that I am...
8
1901
by: Jack Carter | last post by:
I have been delegated to produce a tool that has python embedded in it. The desire is to have a command line interface that inherits all the python scripting functionality so people can use the tool either with a flat commandline entry like you would a debugger or with a script using scoping, loops and conditional. I am going from knowing nothing about python to almost nothing so the learning curve is rather
29
2477
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules" for when and how to use single quotes and double quotes in ASP? thanks! ---------------------- SQL = SQL & "WHERE '" & REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE("GenKTitles.
2
1847
by: The Plankmeister | last post by:
Hi, I am converting some queries from stored procedures in MS Access to MySQL, and have hit my first problem. The Access query references another stored procedure, which is where the problem lies. I have the following table data: (apologies if the columns aren't aligned properly... it looks ok in a fixed-width font) img_num img_page img_sect img_order
9
3140
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
2
1325
by: Laphan | last post by:
Hi All Sorry for the spare info. It wasn't because I didn't want to display it. I just didn't know how to get the data that you needed. I think I've got it now so please note the following: 1) The DB is SQL 6.5. 2) My DDL for the tables in question:
3
5395
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says there is a sample file called Ixtrasp.asp, but I could not find it in my system although I installed indexing service. I followed the steps in MSDN site to create a basic .asp query form (too long to post it here), but it always displays: No...
4
2156
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets over the years. The idea is that from any widget in the database you can look forward and backward to see different versions of the widget through the years. Here are the tables: WIDGETS widget_id name
4
1312
by: Lumpierbritches | last post by:
I have a query that pulls information for a report. Sometimes the report is in tact and works wonderful; other times the report gives me a syntax error. The information is only different in one field where - (dashes) are used to hyphenate Primary ID's for Animals. The ID's where there are no dashes appear to populate the report without any problems. The ID's with the dashes I get a syntax error. Michael
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.