I have a table containing a field called ChannelId. I want to break it out into two fields depending on the value. I tried this:
SELECT CustomerId, ChannelId = 1 as Chan1, ChannelId = 2 as Chan2 FROM ....
The goal being that I have two boolean columns representing whether the ChannelId field is of the approriate value. I get a syntax error.
Looking at the SQL Syntax I can’t see any reason why I can’t use an expression and then alias it as a new column name, but SQL Server croaked on it. Am I doing something really dumb? How can I achieve this effect?
You have to perform an expression, not an assignment, and it depends on he flavor of SQL. Since you’re using SQL Server (T-SQL):
There might be a better way to do it, but that’s how I do it.