Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
I have an requirement for SP in Sql Server
If Agent.FirstName and Agent.LastName in Agent_Hierarchy is Null Then' I need to Pick
Agent.FirstName and Agent.LastName from hagent of Different Data base. The below is my Code but i am unable to get the result


Any one can find soln..
SQL
CREATE PROCEDURE [dbo].[WIN_IdleHoursAgent]          
(                          
@StartDate AS SMALLDATETIME  
         
)        
AS                 
DECLARE                           
@SQL VARCHAR(MAX)
@AgentName VARCHAR(MAX)   
SET @AgentName=ISNULL(AH.Agent_LastName,[CS_RAW_DATA].[dbo].[hagent].[Item_Name]) AND ISNULL(AH.Agent_LastName,[CS_RAW_DATA].[dbo].[hagent].[Item_Name])               
SELECT @AgentName=@AgentName
BEGIN        
 SET @SQL = '       
SELECT @AgentName As Agent_Name,      
       x.LogId As Agent_Id)x LEFT JOIN [WEDW].[dbo].[Agent_Hierarchy] AS AH
END  
Posted
Updated 20-Aug-14 4:44am
v2

1 solution

ISNULL is a function that reurns a default value when the target expression is null. I think that you want:
AH.Agent_LastName,[CS_RAW_DATA].[dbo].[hagent].[Item_Name] IS NULL

This returns TRUE when the field is null
 
Share this answer
 
Comments
sahmed3 20-Aug-14 10:35am    
Thanks Philnomer i will try and let u know
sahmed3 20-Aug-14 14:00pm    
It Worked ISNULL(AH.Agent_LastName +'',''+ AH.Agent_FirstName,A.ITEM_NAME) As Agent_Name,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900