sql - Msg 178, Level 15, State 1, Line 8 A RETURN statement with a return value cannot be used in this context -
i received error message while trying execute below sql.
error:
msg 156, level 15, state 1, line 5 incorrect syntax near keyword 'function'. msg 178, level 15, state 1, line 8 return statement return value cannot used in context.
sql:
if (not exists (select * dbo.tracking cr = 123)) begin create function [dbo].[udfdate]() returns datetime begin return cast('9999-12-31' datetime) end end
am not allowed create function inside if statement ?
you cannot create function inside if statment way following warning
incorrect syntax:
create function
must statment in batch
you can creating variable stor create query in variable , execute it:
if (not exists (select * dbo.tracking cr = 123)) begin declare @strquery varchar(max) set @strquery = ' create function [dbo].[udfdate]() returns datetime begin return cast(''9999-12-31'' datetime) end ' exec(@strquery) end
but didn't understand why creating function return static value??!!
Comments
Post a Comment