这是一个基于好奇心的问题。我试图解决以下问题:
以下是代码:
ALTER PROC [dbo].[Inventory_pr_rpt_Scanfile_InvalidColorSize]
(
@STORE CHAR(3)
)
AS
--set statistics io on
/** TEST **/
--DECLARE @STORE CHAR(3)
--SET @STORE = '180'
/** Drop existing temp table **/
IF OBJECT_ID('tempdb..#TEMP_ScanBadData') IS NOT NULL
DROP TABLE #TEMP_ScanBadData
IF OBJECT_ID('tempdb..#TEMP_ScanDiscrepancy') IS NOT NULL
DROP TABLE #TEMP_ScanDiscrepancy
IF OBJECT_ID('tempdb..#TEMP_ScanFinalReport') IS NOT NULL
DROP TABLE #TEMP_ScanFinalReport
CREATE TABLE #TEMP_ScanBadData (scan_store char(3)
,scan_sku char(45)
,scan_qty int
,errormessage varchar(255))
CREATE TABLE #TEMP_ScanFinalReport(scan_store char(3)
,scan_sku char(45)
,scan_qty int
,storeOH_qty int
,errormessage varchar(255))
CREATE TABLE #TEMP_ScanDiscrepancy(scan_store char(3)
,scan_sku char(45)
,scan_qty int
,storeOH_qty int
,errormessage varchar(255))
/** Does SKU exist in our system? (Valid color/size/style check) **/
INSERT INTO #TEMP_ScanBadData (scan_store
,scan_sku
,scan_qty
,errormessage)
SELECT scan_store
,scan_sku
,scan_qty
,'SKU does not exist.' as errormessage
FROM [LP].[dbo].[scan_file]
WHERE scan_sku NOT IN (SELECT ItemID
FROM [Product].[dbo].[MasterSKU])
AND scan_store = @STORE
/** Does scanned SKU exist in store on hand? **/
INSERT INTO #TEMP_ScanDiscrepancy (scan_store
,scan_sku
,scan_qty
,storeOH_qty
,errormessage)
SELECT aa.scan_store
,aa.scan_sku
,aa.scan_qty
,'' as storeOH_qty
,'Scanned SKU missing in store OH.' as errormessage
FROM [LP].[dbo].[scan_file] aa
FULL OUTER JOIN [Product].[dbo].[CurrentOnHand] bb
ON aa.scan_sku = bb.ItemID
and aa.scan_store = bb.Store
WHERE bb.ItemID IS NULL
AND aa.scan_store = @STORE
and bb.Store = @STORE
/** Were any store OH SKU's missed in scan? **/
INSERT INTO #TEMP_ScanDiscrepancy (scan_store
,scan_sku
,scan_qty
,storeOH_qty
,errormessage)
SELECT aa.Store as 'scan_store'
,aa.ItemId as 'scan_sku'
,aa.OnHandU as 'scan_qty'
,'' as storeOH_qty
,'SKU was not scanned.' as errormessage
FROM [Product].[dbo].[CurrentOnHand] aa
LEFT JOIN [LP].[dbo].[scan_file] bb
ON aa.ItemID = bb.scan_sku
and aa.Store = bb.scan_store
WHERE bb.scan_sku IS NULL
AND aa.Store = @STORE
and bb.scan_store = @STORE
/** What are the qty differences between scanned and OH? **/
INSERT INTO #TEMP_ScanDiscrepancy (scan_store
,scan_sku
,scan_qty
,storeOH_qty
,errormessage)
SELECT aa.scan_store
,aa.scan_sku
,aa.scan_qty
,bb.OnHandU as 'storeOH_qty'
,'QTY does not match between scan and store OH.' as errormessage
FROM [LP].[dbo].[scan_file] aa
JOIN [Product].[dbo].[CurrentOnHand] bb
ON bb.ItemId = aa.scan_sku
AND aa.scan_store = bb.Store
WHERE bb.Store = @STORE
AND bb.OnHandU <> aa.scan_qty
AND aa.scan_store = @STORE
INSERT INTO #TEMP_ScanFinalReport (scan_store
,scan_sku
,scan_qty
,storeOH_qty
,errormessage)
SELECT scan_store
,scan_sku
,scan_qty
,storeOH_qty
,errormessage
FROM #TEMP_ScanDiscrepancy
INSERT INTO #TEMP_ScanFinalReport (scan_store
,scan_sku
,scan_qty
,storeOH_qty
,errormessage)
SELECT scan_store
,scan_sku
,scan_qty
,'' as storeOH_qty
,errormessage
FROM #TEMP_ScanBadData
SELECT *
FROM #TEMP_ScanFinalReport
解决方案:在尝试VARCHAR(3)和CHAR(3)后,我尝试了NCHAR(3),这很有用!
我的问题是:为什么?如果我查看了我引用的每个表,并看到Store的列始终是CHAR(3),我创建的所有临时表都是CHAR(3),为什么NCHAR(3)有效?
我觉得它与SSRS如何将文本变量传递到存储过程中有关...但是对于我如何在sql服务器上运行存储过程仍然没有意义。变量设置为CHAR,VARCHAR和NCHAR。为什么这三个都在sql server上工作,但只有NCHAR通过SSRS使用变量?
表格信息: