Hi everyone,
I'm trying to write a Table-valued function that returns a different set of data for a person depending on a boolean parameter.
I'm trying to achieve something like this...with an if statement to inverse the order of my coalesce depending on if I want primarly unicode values or not. I've done it with a case statement but it require a case per column which is not ideal.
It doesn't work at all, throwing errors at the IF statement, are you not allowed to break the flow of a select statement to select different info?
Thanks for the help!
I'm trying to write a Table-valued function that returns a different set of data for a person depending on a boolean parameter.
I'm trying to achieve something like this...with an if statement to inverse the order of my coalesce depending on if I want primarly unicode values or not. I've done it with a case statement but it require a case per column which is not ideal.
Code:
create function dbo.GetInfo(@ID int, @languageID int, @bOrder bit)
returns table
as
return (
select
IF (bOrder = 1)
BEGIN
coalesce(firtName, firstNameUNIcode) as firstName,
coalesce(lastName, lastNameUNIcode) as lastName
END
ELSE
coalesce(firstNameUNIcode, firstName,) as firstName,
coalesce(lastNameUNIcode, lastName) as lastName
FROM
tblPerson
LEFT OUTER JOIN tblPersonUNICODE on tblPerson.personID = tblPersonUNICODE.fkPersonID
AND tblPersonUNICODE.fkLangID = @languageID
WHERE tblPerson.personID = @ID
)
It doesn't work at all, throwing errors at the IF statement, are you not allowed to break the flow of a select statement to select different info?
Thanks for the help!