SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 more results expected
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rvgeffen
Starting Member

Netherlands
2 Posts

Posted - 08/26/2014 :  02:32:07  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
2067 Posts

Posted - 08/26/2014 :  02:42:23  Show Profile  Visit jackv's Homepage  Reply with Quote
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

Netherlands
2 Posts

Posted - 08/26/2014 :  02:54:14  Show Profile  Reply with Quote
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

Edited by - rvgeffen on 08/26/2014 05:09:13
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
2067 Posts

Posted - 08/27/2014 :  02:20:06  Show Profile  Visit jackv's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000