Hi I have a stored procedure which returns DBNULL if "Line" is empty rather than returning "EquipmentNumbe r":
Error messege "Unable to cast object of type 'System.DBNull' to type 'System.String' ."
Code:
ALTER PROCEDURE [dbo].[sp_get_distinct_lines] @Department varchar(50) AS IF EXISTS (SELECT Line FROM Equipment WHERE Department = @Department) SELECT DISTINCT Line FROM Equipment WHERE Department = @Department ELSE SELECT DISTINCT EquipmentNumber FROM Equipment WHERE Department = @Department
Comment