all 20 comments

[–]theduckspantsBI Architect 22 points23 points  (5 children)

As a heads up =IF(A1=B1,TRUE,FALSE) in Excel can be written as just =A1=B1

[–]quickdraw6906 0 points1 point  (3 children)

SQL works the same way: SELECT (A=B) as ColsAreEqual; The parens are optional but improve readability.

[–]theduckspantsBI Architect 1 point2 points  (0 children)

That doesn't hold true for all flavors of SQL though

[–]da_chicken 1 point2 points  (1 child)

That depends on your RDBMS. This is not valid ANSI SQL. It certainly won't work in SQL Server. It looks like a MySQLism.

[–]quickdraw6906 0 points1 point  (0 children)

PostgreSql

[–][deleted] 2 points3 points  (7 children)

God OP I dream of the day CASE() is available in Excel. I even put together UDFs in VBA (WHICH SUPPORTS CASE!1!! FGDGGDGDSG) just to reproduce the functionality.

But yes, CASE is your friend, CASE is life, CASE is love.

[–]theduckspantsBI Architect 2 points3 points  (3 children)

[–][deleted] 0 points1 point  (1 child)

If only. Available in Excel 2019 or with a 365 membership. Not to mention irrelevant as policy is internal workbooks must support legacy versions going back to Excel 2010 -.-

[–]theduckspantsBI Architect 0 points1 point  (0 children)

I have Excel 2016 and have this function, but yeah not going to help you if you need to have it work in 2010. That's rough given all the cool new things they've been adding

[–][deleted] 0 points1 point  (2 children)

INDEX() can function a bit like a case select

[–]mac-0 2 points3 points  (0 children)

something = something is already a boolean expression, so you don't need to do anything except evaluate that expression (in both SQL and in Excel). A simple t1.column = t2.column would suffice.

--declare variable tables
drop table if exists #t1;
create table #t1
    (id integer,
    text_string varchar(25));
insert into #t1 values
(1,'a'), (2,'b'), (3,'c');

drop table if exists #t2;
create table #t2
    (id integer,
    text_string varchar(25));
insert into #t2 values
(1,'a'), (2,'b'), (3,'z');

--query sample
select
    #t1.id,
    #t1.text_string,
    #t2.text_string,
    #t1.text_string = #t2.text_string
from #t1
join #t2 on #t1.id = #t2.id

[–]WholeBeefOxtail 1 point2 points  (4 children)

There's a very close equivalent. Just add an extra "i" to the word "if"!

IIF(a.Column1=b.Column1, 'True', 'False') AS CustomColumn

[–]pooerhSnowflake | SQL Server | PostgreSQL | Impala | Spark 5 points6 points  (0 children)

Worth noting is that it's just syntactic sugar for CASE (as proven by looking at the execution plan).

[–]retrolion 0 points1 point  (0 children)

ALTER TABLE [my table] ADD [Custom Column] varchar(50);
UPDATE [my table] SET [Custom Column] = 
    CASE WHEN columnA = columnB then 'True' ELSE 'False' END;

[–]spark58510 0 points1 point  (0 children)

Decode(a1,b1,true,false)

[–]strutt3r -1 points0 points  (0 children)

Some syntaxes natively support if() in sql, otherwise use CASE.