In a query selection I would like to display the result whether a field satisfies a condition.
Imagine that I have a table called stock
. This table has a column that tells me the number of each item in the stock.
What I would like to do is something like this:
SELECT
stock.name, IF (stock.quantity <20, "Buy urgent", "There is enough")
FROM stock
Is there any function in SQL Server to do that?
This question is related to
sql
sql-server
sql-server-2008
tsql
Have a look at CASE statements
http://msdn.microsoft.com/en-us/library/ms181765.aspx
Source: Stackoverflow.com