Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 more results expected

Author  Topic 

rvgeffen
Starting Member

5 Posts

Posted - 2014-08-26 : 02:32:07
Hello

When I use the code below, I get when the search doesn't find a match a 'NONE' (as expected). But when I expect two values (because in the table are two matches) I receive just one match?
Who can help me??

USE [DM]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE [dbo].[SIP_rpt_R9000_PD_BOM]
@ProdHeaderDossierCode T_Code_ProdHeadDossier = NULL,
@ProductheaderdoscodeBOM T_Code_ProdHeadDossier = NULL
AS
BEGIN
SET NOCOUNT ON;
select
@ProductheaderdoscodeBOM=PHPL.ProdHeaderDossierCode
FROM T_ProdHeadProdBomLink as PHPL
WHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCode
if @@ROWCOUNT=0
set @ProductheaderdoscodeBOM='NONE'
select @ProductheaderdoscodeBOM '@ProductheaderdoscodeBOM'
return 0
END

RvGeffen

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2014-08-26 : 02:42:23
You'll need to either run the final select statement as :
select PHPL.ProdHeaderDossierCode
FROM T_ProdHeadProdBomLink as PHPL
WHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCode



Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

rvgeffen
Starting Member

5 Posts

Posted - 2014-08-26 : 02:54:14
Thanks for your help, but;

I did made the change. I get two results when I expect two results, so this is solved. But now I do not get the NONE when the search query is empty?

USE [DM]
GO
/****** Object: StoredProcedure [dbo].[SIP_rpt_R9000_PD_BOM] Script Date: 08/26/2014 11:04:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE [dbo].[SIP_rpt_R9000_PD_BOM]
@ProdHeaderDossierCode T_Code_ProdHeadDossier = NULL,
@ProductheaderdoscodeBOM T_Code_ProdHeadDossier = NULL
AS
BEGIN
SET NOCOUNT ON;
select
@ProductheaderdoscodeBOM=PHPL.ProdHeaderDossierCode
FROM T_ProdHeadProdBomLink as PHPL
WHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCode
if @@ROWCOUNT=0
set @ProductheaderdoscodeBOM='NONE'
select @ProductheaderdoscodeBOM
FROM T_ProdHeadProdBomLink as PHPL
WHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCode
return 0
END
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2014-08-27 : 02:20:06
Use the the IF .. ELSE syntax

IF @@rowcount = 0
BEGIN
place in here logic for return if rowcount = 0
END
ELSE
BEGIN
place in here logic for rows returned if rowcount > 0
END



Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -