Hi all!,
These are my tables:
CREATE TABLE #A ( StorerKey int NOT NULL, Sku varchar(30) NOT NULL, LOT1 varchar(10) NULL,LOT2 varchar(10) NULL,LOT3 varchar(10) NULL,LOT4 varchar(10) NULL,LOT15varchar(10) NULL,LOT6 varchar(10) NULL ) INSERT INTO #A VALUES (1,123,2,1,12,1.5,1.511,CP)
CREATE TABLE #B ( StorerKey int NOT NULL, Sku varchar(30) NOT NULL, LOT15 varchar(10) NULL,LOT16 varchar(10) NULL,LOT17 varchar(10) NULL,LOT18 varchar(10) NULL,LOT19varchar(10) NULL,LOT20 varchar(10) NULL ,LOT21 varchar(10) NULL,LOT22 varchar(10) NULL,LOT23 varchar(10) NULL,LOT24 varchar(10) NULL,LOT25 varchar(10) NULL,LOT26 varchar(10) NULL) INSERT INTO #B VALUES (1,123,1,1,1,1,1,1,1,1,1)
I need to retrieve different fields from two tables.
If I use query 1 to generate from table A, I get 1 record
SELECT #A.STOREKEY,#A.SKU,#A.LOT1,#A.LOT2,#A.LOT3,#A.LOT4,#A.LOT5,#A.LOT6
FROM #A WHERE #A.lot7='001' AND #A.sku='123' and #A.STORERKEY='1'
If I use query 2 to generate from table B, I get 1 record also
SELECT #B.STORERKEY,#B.SKU,#B.LOT15,#B.LOT16,#B.LOT17,#B.LOT18,#B.LOT19,#B.LOT20,#B.LOT21,#B.LOT22,#B.LOT23,#B.LOT24
FROM #B WHERE #B.sku='123' and #B.STORERKEY='1'
But when I used query 3, I get 2 record instead (Like Results)
SELECT #A.STOREKEY,#A.SKU,#A.LOT1,#A.LOT2,#A.LOT3,#A.LOT4,#A.LOT5,#A.LOT6,#B.STORERKEY,#B.SKU,#B.LOT15,#B.LOT16,#B.LOT17,#B.LOT18,#B.LOT19,#B.LOT20,#B.LOT21,#B.LOT22,#B.LOT23,#B.LOT24
FROM #A TA
JOIN #B TB ON TA.SKU=TB.SKU WHERE #A.lot7='001' AND #A.sku='123' and #A.STORERKEY='1'
I just need the results from 2 tables to combine into 1 record (Like the desired record)
What's wrong with my query 3?=(
Thank you in advance!