| 
                
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 |  
                                    | GabrielApStarting Member
 
 
                                        3 Posts | 
                                            
                                            |  Posted - 2013-06-29 : 21:52:58 
 |  
                                            | Hello guys, I created a function that returns a table but I have to check if the table is empty if the table is empty I have to return a message, does anyone know how to perform the check if the table is empty? And return a message?Here is my function:REATE FUNCTION FNC_GANHADORES(@COD_PARTIDA INTEGER, @NOME_TIMEA VARCHAR(100),@PLACAR_TIMEA INTEGER, @NOME_TIMEB VARCHAR(100), @PLACAR_TIMEB INTEGER)RETURNS TABLEASRETURNSELECT FKIDUSUARIO FROM APOSTA AINNER JOIN PARTIDA ON (A.APOSTAPLACARSELECAO_A = PARTIDA.PLACARSELECAR_A)WHERE PLACARSELECAR_A = @PLACAR_TIMEA AND PLACARSELECAO_B = @PLACAR_TIMEB |  |  
                                    | James KMaster Smack Fu Yak Hacker
 
 
                                    3873 Posts | 
                                        
                                          |  Posted - 2013-06-29 : 23:31:32 
 |  
                                          | Who is the consumer of the function? If you are using the function in  your own code, then you can add the check to see if there are any rows in the table that is returned and generate the appropriate message. |  
                                          |  |  |  
                                    | GabrielApStarting Member
 
 
                                    3 Posts | 
                                        
                                          |  Posted - 2013-06-30 : 11:16:14 
 |  
                                          | Sim eu mesmo realizo a chamada da funcao estou fazendo desta forma: Select * from [dbo].[fnc_ganhadores](1,"Brasil",1,"Japao",2) porem nao sei como faco para realizar a verificação na chamada da função, voces podem me ajudar? Desde ja Obrigado. |  
                                          |  |  |  
                                    | MuMu88Aged Yak Warrior
 
 
                                    549 Posts | 
                                        
                                          |  Posted - 2013-06-30 : 13:12:36 
 |  
                                          | Tente usar COUNT () operador, se ele retorna> = 1, em seguida, completar a sua chamada de erro de retorno esle função ou aviso.[CODE]Select COUNT(1) from [dbo].[fnc_ganhadores](1,"Brasil",1,"Japao",2)[/CODE] |  
                                          |  |  |  
                                    | GabrielApStarting Member
 
 
                                    3 Posts | 
                                        
                                          |  Posted - 2013-06-30 : 14:09:57 
 |  
                                          | Muito obrigado pela ajuda gente, MuMu88 e James K,  sabia que encontraria ajuda aqui.A resolução ficou assim:DECLARE @NUM INTEGERSET @NUM = (SELECT COUNT (1) FROM [dbo].[FNC_GANHADORES](1,'BRASIL',0,'JAPAO',2))BEGIN	IF @NUM = 0 PRINT 'NENHUMA APOSTA'ELSESELECT * FROM [dbo].[FNC_GANHADORES](1,'BRASIL',0,'JAPAO',2)END |  
                                          |  |  |  
                                    | MuMu88Aged Yak Warrior
 
 
                                    549 Posts | 
                                        
                                          |  Posted - 2013-06-30 : 15:37:51 
 |  
                                          | nós estamos contentes de ajudar |  
                                          |  |  |  
                                |  |  |  |  |  |