sql - If statement to determine which SELECT to return in Table-Valued Function -
due recent change in business rules, set of data used stored in 1 database , stored in different database on same server. things set up, if user wants query data range of dates overlaps time when business rules changed, they're forced use if statement in code.
i create table-valued function abstract change in business rules users making such query. i'm trying execute code similar this:
create function dbo.somefunction (date datetime) returns table return if (date <= business_rules_change_date) begin select (a select statement) (old database) (criteria) end else select (a similar select statement) (new database) join (a join statement) (criteria) go
and i'm being told there syntax error around if statement. there solution problem?
or yuriy has suggested can make use of multi-statement-table valued functions this...
create function dbo.somefunction (date datetime) returns @table table ( -- define structure of table here ) begin if (date <= business_rules_change_date) begin insert @table select (a select statement) (old database) (criteria) end else begin insert @table select (a similar select statement) (new database) join (a join statement) (criteria) end return end
Comments
Post a Comment