sql - Why does nchar variable work when the columns referenced are char? -
this question based on curiosity. trying solve following problem:
- my stored proc produces results within 1-2 seconds of running, no problems.
- when run proc through ssrs, page gets stuck on loading , never produces results. takes 30 seconds - 1 minute become unstuck , quit processing query.
- any table referencing/joining on variable has same data type, char(3).
below code:
alter proc [dbo].[inventory_pr_rpt_scanfile_invalidcolorsize] ( @store char(3) ) --set statistics io on /** test **/ --declare @store char(3) --set @store = '180' /** drop existing temp table **/ if object_id('tempdb..#temp_scanbaddata') not null drop table #temp_scanbaddata if object_id('tempdb..#temp_scandiscrepancy') not null drop table #temp_scandiscrepancy if object_id('tempdb..#temp_scanfinalreport') 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)) /** sku exist in our system? (valid color/size/style check) **/ insert #temp_scanbaddata (scan_store ,scan_sku ,scan_qty ,errormessage) select scan_store ,scan_sku ,scan_qty ,'sku not exist.' errormessage [lp].[dbo].[scan_file] scan_sku not in (select itemid [product].[dbo].[mastersku]) , scan_store = @store /** scanned sku exist in store on hand? **/ insert #temp_scandiscrepancy (scan_store ,scan_sku ,scan_qty ,storeoh_qty ,errormessage) select aa.scan_store ,aa.scan_sku ,aa.scan_qty ,'' storeoh_qty ,'scanned sku missing in store oh.' errormessage [lp].[dbo].[scan_file] aa full outer join [product].[dbo].[currentonhand] bb on aa.scan_sku = bb.itemid , aa.scan_store = bb.store bb.itemid null , aa.scan_store = @store , bb.store = @store /** store oh sku's missed in scan? **/ insert #temp_scandiscrepancy (scan_store ,scan_sku ,scan_qty ,storeoh_qty ,errormessage) select aa.store 'scan_store' ,aa.itemid 'scan_sku' ,aa.onhandu 'scan_qty' ,'' storeoh_qty ,'sku not scanned.' errormessage [product].[dbo].[currentonhand] aa left join [lp].[dbo].[scan_file] bb on aa.itemid = bb.scan_sku , aa.store = bb.scan_store bb.scan_sku null , aa.store = @store , bb.scan_store = @store /** qty differences between scanned , oh? **/ insert #temp_scandiscrepancy (scan_store ,scan_sku ,scan_qty ,storeoh_qty ,errormessage) select aa.scan_store ,aa.scan_sku ,aa.scan_qty ,bb.onhandu 'storeoh_qty' ,'qty not match between scan , store oh.' errormessage [lp].[dbo].[scan_file] aa join [product].[dbo].[currentonhand] bb on bb.itemid = aa.scan_sku , aa.scan_store = bb.store bb.store = @store , bb.onhandu <> aa.scan_qty , aa.scan_store = @store insert #temp_scanfinalreport (scan_store ,scan_sku ,scan_qty ,storeoh_qty ,errormessage) select scan_store ,scan_sku ,scan_qty ,storeoh_qty ,errormessage #temp_scandiscrepancy insert #temp_scanfinalreport (scan_store ,scan_sku ,scan_qty ,storeoh_qty ,errormessage) select scan_store ,scan_sku ,scan_qty ,'' storeoh_qty ,errormessage #temp_scanbaddata select * #temp_scanfinalreport resolution: after trying varchar(3) , char(3), tried nchar(3), , worked!
my question is: why? if viewed each table referencing , saw column store char(3), , temp tables created char(3), why nchar(3) work?
i feel has how ssrs passes text variable stored proc...but still doesn't make sense me how can run stored proc on sql server variable set char, varchar, , nchar. why 3 work on sql server, nchar works variable through ssrs?
table information:
- [lp].[dbo].[scan_file]
- scan_store char(3)
- [product].[dbo].[currentonhand]
- store varchar(4)
Comments
Post a Comment