Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

SQL: Handle Duplicated or NULL or Blank or Wrong parameter values by user input

$
0
0

Dear Experts

I have 2 questions for handling 2 cases with using the below stored procedure.


My sp here:

ALTER PROCEDURE [dbo].[sp_chk_itemcode]
@item_code nvarchar(4000)
AS
BEGIN

SET NOCOUNT ON;

select 
im.item_code AS item_code,
im.item_detail AS item_detail

from item_master im
LEFT JOIN latest_one_invoice_price latest_one_invoice_price on latest_one_invoice_price.item_code = im.item_code
AND latest_one_invoice_price.company_code = im.company_code

LEFT JOIN lpptable('COM-001') lpp on im.item_code=lpp.item_code and im.company_code=lpp.company_code 
left join item_vendor iv on im.item_code_real=iv.item_code_real and im.company_code=iv.company_code and iv.vendor_code = lpp.vendor_code
left join (select pi.item_code, sum(pi.qty) as PO_qty from purorder_master pm 
left JOIN purorder_item pi ON pm.purorder_no_real=pi.purorder_no_real AND pm.company_code=pi.company_code
where pm.purorder_date >= '2009-04-01 00:00:00.000'  and pm.cancelled <> 1 
group by pi.item_code) po on po.item_code = im.item_code

where

(@item_code LIKE '*' OR (upper(im.item_code) IN (SELECT VALUE FROM dbo.FnSplit(@item_code,','))))

ORDER BY charindex(im.item_code, @item_code)
END

BTW, this sp will also be used for SSRS 2008.

Does any experts can help on this? Thank you so much!

(Sorry for my poor illustration. Please bear with me.)


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>