Instead of IF-ELSE you need to use
CASE[
^]
Here is a CodeProject article on the subject
A Simple Use of SQL CASE Expression[
^].
Member 10694442 said:
& i want to do this for all 4000 rows
Be aware that if you don't filter your SQL query using a
WHERE[
^] clause then it will affect every row on the table - more information
here[
^].
In your case this would work:
select CASE WHEN [close] > [ref] THEN 'Buy' ELSE 'Sell' END
from YourTable
Notice that I have surrounded the column names with square brackets because
close
is one of SQL Server's
reserved words[
^]. It is best practise to avoid using reserved words as column or variable names.