Reputation: 2263
I'm making a database view in MS SQL server 2008 R2. One of the output columns, named 'Status', pulls information about an entity from several different tables to produce a string status that is reported to the user.
I'm therefore creating a function which takes the entity ID as the only parameter and returns the nvarchar(MAX) status.
The first check is whether or not the entity has been approved. This is stored in the database as the username of the person that approved it. If it is not approved, the value is NULL.
So, pseudo-code for what I want to do is this:
if entity is NOT approved
return "Pending"
else
begin
max = select MAX(value) from EntityStatus // several statuses may exist
status = select name from EntityStatus WHERE value = max
return status
end
My immediate problem is: How do I select the 'approved' boolean?
I'm very new to T-SQL programming (it probably shows) so feel free to suggest other ways I can improve my function.
Upvotes: 0
Views: 4417
Reputation: 128
try this
select city,isnull(city,'pending/unknown')city2 from authors
Upvotes: 0
Reputation: 56769
if (select approver_username from approvals where entityid = @entityid) is null
return 'Pending'
else
begin
...
end
Upvotes: 1