Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:49:23+00:00 2026-06-12T08:49:23+00:00

I have a simple table running in SQL Server 2005 defined as CREATE TABLE

  • 0

I have a simple table running in SQL Server 2005 defined as

CREATE TABLE [dbo].[ap_purchases_tax_det](
[invoice_s] [int] NOT NULL,
[line_num] [smallint] NOT NULL,
[tax_code] [varchar](10) NOT NULL,
[tax_type] [varchar](2) NULL,
[tax_det_s] [int] IDENTITY(1,1) NOT NULL,
[old_entity] [varchar](14) NULL,
[old_cc_code] [varchar](5) NULL,
[old_vendor] [varchar](15) NULL,
[old_invoice] [varchar](20) NULL,
[citi] [varchar](1) NULL,
CONSTRAINT [aaaaaap_purchases_tax_det_PK] PRIMARY KEY NONCLUSTERED 
(
    [invoice_s] ASC,
    [line_num] ASC,
    [tax_code] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

The tax_type field is filled with either ‘W’, ‘V’, ‘B”, or ” (this one is not NULL).

I need to get a boolean flag if tax_type is ‘W’, so I have the SQL:

select iif(tax_type = 'W',1,0) FROM dbo.ap_purchases_tax_det;

when I run this I get “Incorrect syntax near ‘=’.”. This occurs even for a simple tax_type = 'W'. The test for equality seems to work in the WHERE clause, but I need a flag, which means I would have to UNION together 2 selects. This is actually part of a join that is a subquery in much larger statement so I don’t want to do this. I have tried excplicitly casting tax_type = cast('W' as varchar(2)) to no avail. Same results if I use ISNULL(tax_type,'x').

I have no idea why the test for equality is not working, can someone provide guidance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:49:24+00:00Added an answer on June 12, 2026 at 8:49 am

    Generally, write the IIF like this prior to SQL Server 2012

    select case when tax_type = 'W' then 1 else 0 end
    FROM dbo.ap_purchases_tax_det;
    

    The CASE statement has another form, but that’s like a SWITCH statement in C#/Java or SELECT CASE in MS Access, which is not really a general conditional.

    Two important notes about IIF (Transact-SQL)

    IIF is a shorthand way for writing a CASE statement.
    The fact that IIF is translated into CASE…

    So when you write

    IIF ( {condition} , {true} , {false} )
    

    The SQL Server query optimizer literally sees

    CASE WHEN {condition} THEN {true} ELSE {false} END
    

    FYI You can avoid the CASE statement completely by using this

    SELECT 1-sign(abs(ascii('W')-ascii(tax_type+'.')))
    

    Just a thought.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a simple query running against SQL Server 2005 SELECT * FROM Table
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
edit: SQL Server 2005 I have a customer application running on 5 separate servers.
I have simple table creating script in Postgres 9.1. I need it to create
I have a simple table with autoincrementing ID's and one text column. id(int), value(nvarchar)
I have a simple table in Sybase, let's say it looks as follows: CREATE
Running SQL Server 2008, and I am definitely a new SQL user. I have
I have a SQL Server database running in Full recovery. I need to remove
I have recently been running into many different areas of SQL Server that I
I have a view defined in SQL server 2008 that joins 4 tables together.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.