tsql - Stored Procedure vs User Defined Function for Error Handling -


my erp database uses non-nullable datetime fields. however, enters '' datetime when 1 isn't available , returns ‘1900-01-01 00: 00: 00.000’ value.

i want suppress 1900 dates while stripping date datetime field. created following udf that:

create function extractdate(@dirtydate datetime)   returns varchar(10)   begin     declare @cleandate varchar(10)     select @cleandate =              case                when @dirtydate = '' ''                else convert(varchar(10), @dirtydate, 101)              end      return @cleandate   end 

this works, wanted add error handling in case user used on other datetime field. after googling, found out isn't possible udf.

however, if write stored procedure, still able call in select statement? can point me in right direction?

no, can't call stored proc in select statement.

i applaud ambition in wanting include error handling, best bet check on app side - don't allow people use function on non-date fields.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -