Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i hve one stored procedure

SQL
create PROCEDURE spgetoutpatientidbyinpatientid
@pinpatientid int
AS

BEGIN

    select  Patient_ID from tblPatientAdmissionDetails where ID=@pinpatientid and Status=1
END
GO


if this condition is wrong i got null exception.i want to return at least null value or anything.how can i avoid this error
in my code i use

C#
string  ds = UserDataBase.ExecuteScalar(Command).ToString();


how can i change my sql query..?
Posted

Hi,

you can write your query like this :

SQL
create PROCEDURE spgetoutpatientidbyinpatientid
@pinpatientid int = 0
AS

BEGIN

    select  ISNULL(Patient_ID,0) AS Patient_ID from tblPatientAdmissionDetails where ID=@pinpatientid and Status=1
END
GO


Thanks,
Viprat
 
Share this answer
 
v2
Comments
nixon13 26-Oct-12 4:31am    
sorry its not working..i got same exception
VIPR@T 26-Oct-12 4:36am    
have you check that @pinpatientid in this variable value is going to pass or not.
@pinpatientid int = 0
Do like this and try once
nixon13 26-Oct-12 4:50am    
its not working ..i got the answer..declare one variable in stored procedure
VIPR@T 26-Oct-12 5:14am    
see the solution, this is the same thing which i told you. I have given value 0 at parameter.
You can avoid the error by using a variable inside your stored procedure. See the following code block

SQL
create PROCEDURE spgetoutpatientidbyinpatientid
@pinpatientid int
AS
 
BEGIN
    
    DECLARE @PatientId BIGINT;

    SET @PatientId = 0

    select @PatientId = ISNULL(Patient_ID,0) from tblPatientAdmissionDetails where  
    ID=@pinpatientid and Status=1

    SELECT @PatientId
END


Thank you..
 
Share this answer
 
Comments
nixon13 26-Oct-12 4:47am    
hi..thnks..its working..
damodara naidu betha 26-Oct-12 6:45am    
any vote?.. ;)

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