Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
uxphreak
Starting Member
38 Posts |
Posted - 2005-03-17 : 11:19:24
|
| Good morning,I'm trying to find missing data from a table that consists of Product and Location. This table is used to assign a product (SkuID) to a Location (LocID). I want to see which products are not at all locations, and identify which locations are missing. Here is a result of a simple select query:SkuID LocID Qty ---------------- ---------------- ----------- 1-1040 1 01-1040 2 01-1040 3 01-1040 4 01-1040 6 01-1040 7 01-1040 C -11001 1 61001 10 01001 2 51001 3 01001 4 111001 6 91001 7 01001 8 01001 C -61002 1 161002 10 01002 2 31002 3 11002 4 431002 6 01002 7 01002 8 01002 C 1467As you can see in the above query result, some products have LocIDs 1,2,3,4,6,7,8,10, and C, while others have missing locations.Here's the DDL of the table involved:CREATE TABLE [dbo].[ProductLocation] ( [SkuID] [char] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [LocID] [char] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Qty] [int] NULL , [DestLocID] [char] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [ETA] [datetime] NULL , [LocationPrice] [money] NULL , [IsTaxed] [bit] NOT NULL , [StatusID] [int] NOT NULL , [MinLvl] [int] NOT NULL , [MaxLvl] [int] NOT NULL , [rowguid] uniqueidentifier ROWGUIDCOL NOT NULL , [OverrideQty] [int] NULL ) ON [PRIMARY]GOThanks for your assistance.D |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-03-17 : 11:26:59
|
| Do you have a products table?What the sql that generated your output you displayed?Brett8-) |
 |
|
|
uxphreak
Starting Member
38 Posts |
Posted - 2005-03-17 : 11:29:10
|
| Hi Brett,Yes, I have a Product table. Here's the DDL for it:CREATE TABLE [dbo].[Product] ( [SkuID] [char] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Description] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [UPC] [varchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [CatalogCode] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Weight] [float] NULL , [BasePrice] [money] NULL , [StatusID] [int] NOT NULL , [CategoryID] [char] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [RefSkuID] [char] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [rowguid] uniqueidentifier ROWGUIDCOL NOT NULL , [XferInclude] [bit] NOT NULL ) ON [PRIMARY]GOHere's the query I used to get the previous results:select top 25 SkuID, LocID, Qtyfrom productlocationThanks,D |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-03-17 : 11:36:41
|
Run this and paste the results for us. reduce the results with thisSELECT TOP 30 SQL FROM (SELECT 'INSERT INTO ProductLocation (SkuID, LocID, Qty) ' AS SQL, 1 AS SQLOrderUNION ALLSELECT 'SELECT ' + ''''+RTRIM(SkuID)+''','''+ RTRIM(LocID)+''','+CONVERT(varchar(15),Qty)+ ' UNION ALL ' AS SQL, 2 AS SQLOrderFROM ProductLocation) AS XXX ORDER BY SQLOrder Brett8-) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-03-17 : 11:42:46
|
Never mind...This is not tested, but I think you need to do this SELECT p.SkuID, l.LocID FROM Product pCROSS JOIN Location l WHERE NOT EXISTS (SELECT * FROM ProdcutLocation pl WHERE pl.Poduct = p.Product AND pl.Location = l.Location) Brett8-) |
 |
|
|
uxphreak
Starting Member
38 Posts |
Posted - 2005-03-17 : 11:42:55
|
| It's rather large, displaying 25,149 rows. It might be better to e-mail the results in a text file?D |
 |
|
|
uxphreak
Starting Member
38 Posts |
Posted - 2005-03-17 : 12:06:00
|
| Thanks Brett, your last post did the trick. Much appreciated.D |
 |
|
|
|
|
|
|
|