Click here to Skip to main content
15,908,906 members

Comments by mhwasim (Top 21 by date)

mhwasim 28-Mar-12 7:22am View    
Pass Null value not empty string or set the initial values in sp to -1 and pass -1. modify the where clause respectively...but if u set to "" then u'll have to handle this scenario in sp code as well to make it work otherwise it will look into table values.. Integer values cannot be set empty strings or "" set to null
mhwasim 27-Mar-12 8:35am View    
pseudo something like bleow
IF EXISTS (select null from table1 where column1 = @Val)
BEGIN
UPDATE table set column2 = @NEWval where column1 = @Val
SELECT 'Rec updated'
END
ELSE
SELECT 'Rec not found'
mhwasim 27-Mar-12 8:20am View    
this definition will do this for u
CREATE TABLE dbo.PROD_INVENTORY
(PROD_GRP_ID int,PRODUCT_ID int, QTY int,WAREHOUSE_ID int, INV_CAT_ID int)

INSERT INTO PROD_INVENTORY
SELECT 1,1,10,1,1 UNION ALL
SELECT 1,2,20,2,2 UNION ALL
SELECT 1,1,30,3,3 UNION ALL
SELECT 1,3,40,1,4
GO
ALTER PROCEDURE SP1(@wid int=null, @pgid int=null, @pid int=null, @invcat int=null)
AS
BEGIN
select PROD_GRP_ID,PRODUCT_ID,WAREHOUSE_ID, QTY from PROD_INVENTORY
where (WAREHOUSE_ID=@wid or ISNULL(@wid, -1) = -1 ) and
(PROD_GRP_ID=@pgid or ISNULL(@pgid, -1) = -1 ) and
(PRODUCT_ID=@pid or ISNULL(@pid, -1) = -1 ) AND
(INV_CAT_ID=@invcat or ISNULL(@invcat, -1) = -1)

END

GO

sp1 1,1,1,1

i used to simulate it with above example
mhwasim 27-Mar-12 6:33am View    
pls check the expected sp definition I have sent to u in early post...
make the use of OR and AND as per ur requirement
mhwasim 27-Mar-12 6:30am View    
can u provide an example?