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 6857309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:00:01+00:00 2026-05-27T02:00:01+00:00

The following TQL query is generated from a tool I’m using but when it’s

  • 0

The following TQL query is generated from a tool I’m using but when it’s executed there is a syntax error near ‘LIKE’. I can’t seem to figure out what the problem is. Does anybody know what’s wrong?

The error from SQL Management Studio is “Msg 156, Level 15, State 1, Line 17 Incorrect syntax near the keyword ‘LIKE’.”

SELECT COUNT_BIG(*)
FROM [HistoryReport] AS t0
WHERE (1 <> 0 AND 


    (CASE WHEN (
                (CASE WHEN (t0.[CategoryValue] IS NULL) 
                    THEN NULL 
                    ELSE LOWER(t0.[CategoryValue]) 
                END) IS NULL
        ) 
        THEN NULL 
        ELSE (
            (CASE WHEN (t0.[CategoryValue] IS NULL) 
                THEN NULL 
                ELSE LOWER(t0.[CategoryValue]) 
            END) LIKE 'U' + '%'     
        )
    END) <> 0) 
  • 1 1 Answer
  • 1 View
  • 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-05-27T02:00:02+00:00Added an answer on May 27, 2026 at 2:00 am

    A few things, It seems very strange that you are testing if a value is null, and returning null if it is and the value if it isn’t. Then you’re checking for nulls again in the branch of code that is only executed if the value is definitely not null. A bit unnecessary and very confusing. In addition, I suspect your comparison with NULL isn’t going to work the way you think it is since NULL <> 0 will evaluate to NULL by default.

    As an aside: normally, in SQL SERVER, strings are case-insensitive (unless you configure the column or server with a case-sensitive collation which is somewhat uncommon.)

    I’m trying hard to figure out what you actually mean, here is a syntactically correct version of what I think you’re trying to do:

    SELECT COUNT_BIG(*)
    FROM [HistoryReport] AS t0
    WHERE (1 <> 0 AND LOWER(t0.categoryValue) like 'U' + '%')
    

    Basically your query states that if t0.categoryValue is null, return null otherwise convert t0.categoryvalue to lowercase and compare, using like, to ‘U%’ and return true if the LIKE comparison returns true. The query above accomplishes the same thing.

    IF you aren’t using a case-sensitive collation, you can remove LOWER() since it only adds cost and prevents any index usage.

    Now, in SQL Server’s world NULL means ‘unknown’ so asking “Does this unknown value = 0” can only give the answer “I don’t know.” This confuses a lot of people because they expect “NULL==NULL” which works in some languages, but in SQL Sever you’re basically asking “Is this unknown value the same as this other unknown value” and the answer is, again, unknown.

    So I guess my only follow-up question, is how to do you want nulls to be treated?

    Also, as to your original question, it would appear that expressions like your LIKE 'U' + '%' don’t like being in the middle of CASE statements.

    BOL states the syntax is:

    Simple CASE expression: 
    CASE input_expression 
         WHEN when_expression THEN result_expression [ ...n ] 
         [ ELSE else_result_expression ] 
    END 
    Searched CASE expression:
    CASE
         WHEN Boolean_expression THEN result_expression [ ...n ] 
         [ ELSE else_result_expression ] 
    END
    

    and that:

    THEN result_expression Is the expression returned when
    input_expression equals when_expression evaluates to TRUE, or
    Boolean_expression evaluates to TRUE. result expression is any valid
    expression.

    And what you have with LIKE seems like it should be a valid expression but it appears that LIKE is on the fringe of valid operatiors.

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

Sidebar

Related Questions

Following this question: Good crash reporting library in c# Is there any library like
Following up on my earlier query , is there a way to specify the
Following code is used to get images from particular folder but how to get
Following s my Code to display data to listview from database. But it will
Following on from one of the answers in this thread; Using XQuery in Linq
Following on from my recent question on Large, Complex Objects as a Web Service
Following my question regarding a .NET YAML Library ... as there doesn't seem to
Following on from this question what would be the best way to write a
Following techniques from 'Modern C++ Design', I am implementing a persistence library with various
Following on from the question asked by Mykroft Best way to handle input from

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.