MS Visual Studio Query Designer

Is it possible to write an IF statement in Visual Studios Query Designer in the column field?
I've tried a number of iterations that would have worked in MS Access but not luck in Query Designer.
thank you
ShawnGrayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
Yes, the T-SQL equivalent of Access Iif is CASE

SELECT CASE Id WHEN 1 THEN 'banana' WHEN 2 THEN 'orange' ELSE 'grape' END
ShawnGrayAuthor Commented:
Does this have to be written in the SQL pane or can it be written in the Criteria pane?

Table: AdvBase
Field: DistNet

Wanting sql equivalent:
NewField: iif([DistNet]>10000,"big","small")
ValentinoVBI ConsultantCommented:
Does this have to be written in the SQL pane or can it be written in the Criteria pane?

You can write that whole CASE statement (starting with CASE, ending with END) in the Column field.

iif([DistNet]>10000,"big","small")

CASE WHEN DistNet > 10000 THEN 'big' ELSE 'small' END
{edit: replaced double quotes with single quotes}

Please note: the CASE syntax in this statement is different from the one Jim posted.  Jim's example is known as a "simple case expression" while mine is called a "searched case expression".  More details: CASE (Transact-SQL)

I'd also like to advice you to learn the basics of SELECT statement writing.  Once you've gotten the hang of it you'll never use that Query Designer again.  I always write my queries in the Management Studio and paste it into the Dataset Query window when it's fully functional.  Just my 2c, up to you of course to decide if it's worth the effort :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

ShawnGrayAuthor Commented:
ValentinoV
Thanks; the quotes "" are being replaced by Query Designer with brackets [].
Execution error: "Invalid column name 'big', Invalid column name 'small'
ShawnGrayAuthor Commented:
ValentinoV
Disregard last question.  found I needed to define the expression with table.field
Really appreciate the help and the resource.
ValentinoVBI ConsultantCommented:
Thanks; the quotes "" are being replaced by Query Designer with brackets [].

Ooh, just noticed that I mistakingly used double quotes while they should have been single ones.  In T-SQL, double quotes around a string are equivalent to the square brackets but this means SQL Server thinks you're typing an object name, such as a column or a table.  In your case I think you just wanted hard-coded strings, right?

I'll edit my response above to correct this to avoid confusion for any other readers...

Good to hear you got it working though!
ShawnGrayAuthor Commented:
Very good. Thanks for the education.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.