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.
Author |
Topic |
rvgeffen
Starting Member
5 Posts |
Posted - 2014-08-26 : 02:32:07
|
HelloWhen 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]GOSET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER OFFGOALTER PROCEDURE [dbo].[SIP_rpt_R9000_PD_BOM] @ProdHeaderDossierCode T_Code_ProdHeadDossier = NULL, @ProductheaderdoscodeBOM T_Code_ProdHeadDossier = NULLASBEGINSET NOCOUNT ON;select@ProductheaderdoscodeBOM=PHPL.ProdHeaderDossierCodeFROM T_ProdHeadProdBomLink as PHPLWHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCodeif @@ROWCOUNT=0set @ProductheaderdoscodeBOM='NONE'select @ProductheaderdoscodeBOM '@ProductheaderdoscodeBOM'return 0ENDRvGeffen |
|
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.ProdHeaderDossierCodeFROM T_ProdHeadProdBomLink as PHPLWHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCodeJack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
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 OFFGOSET QUOTED_IDENTIFIER OFFGOALTER PROCEDURE [dbo].[SIP_rpt_R9000_PD_BOM] @ProdHeaderDossierCode T_Code_ProdHeadDossier = NULL, @ProductheaderdoscodeBOM T_Code_ProdHeadDossier = NULLASBEGINSET NOCOUNT ON;select@ProductheaderdoscodeBOM=PHPL.ProdHeaderDossierCodeFROM T_ProdHeadProdBomLink as PHPLWHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCodeif @@ROWCOUNT=0set @ProductheaderdoscodeBOM='NONE'select @ProductheaderdoscodeBOMFROM T_ProdHeadProdBomLink as PHPLWHERE PHPL.ProdBOMProdHeaderDossierCode=@ProdHeaderDossierCodereturn 0END |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2014-08-27 : 02:20:06
|
Use the the IF .. ELSE syntaxIF @@rowcount = 0 BEGIN place in here logic for return if rowcount = 0 ENDELSE BEGIN place in here logic for rows returned if rowcount > 0 ENDJack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
|
|
|