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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:44:47+00:00 2026-05-27T18:44:47+00:00

I started to take a look at the following question: https://stackoverflow.com/questions/8616458/sql-query-like-clarification Unfortunately it appeared

  • 0

I started to take a look at the following question: https://stackoverflow.com/questions/8616458/sql-query-like-clarification

Unfortunately it appeared that the original question was somewhat unclear however I decided to interpret this as him trying to only run his query when certain columns in the schema matched his like condition. It’s very possible that this wasn’t what was being asked however I wanted to challenge myself to do this (posted as a new question since the original was unclear and likely to be deleted and very possible nothing related to this).

What I got to was the following:

select 
       [OrderID]
      ,[ProductID]
      ,[UnitPrice]
      ,[Quantity]
      ,[Discount]
from [Northwind].[dbo].[Order Details]
where
    (
        select top 1
                COLUMN_NAME
        from    INFORMATION_SCHEMA.columns
        where   COLUMN_NAME like '%ProductID'
    ) like '%ProductID'

I’m aware how syntactically ridiculous this is however I put it here to give you an idea where my thought process was headed and was also hoping that based on this I could get feedback as to a better method of only running a query when there’s a column in the database that matches a condition that you specify? I don’t see any purpose for it anywhere – I’m just curious and think I could learn from this.

  • 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-05-27T18:44:47+00:00Added an answer on May 27, 2026 at 6:44 pm

    If I understand you correctly you can do it using system view sys.columns:

    IF EXISTS (SELECT 1 FROM sys.columns WHERE name LIKE '%ProductID')
    SELECT *
    FROM [Northwind].[dbo].[Order Details]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since QT license change is announced I started to take a look at the
I have just started to learn Ruby and got a good take on the
Zlib::GzipReader can take an IO, or IO-like, object. as it's input, as stated in
Started with this question: OpenID. How do you logout OK. So OpenID does not
I recently started C++. I am using PHP right now and decided to take
Please take a look at my simple three-methods Service class that streams audio and
Take a look at this simple HTML: <div id=wrap1> <iframe id=iframe1></iframe> </div> <div id=warp2>
I would like to take a list of names (e.g. john, mary, paul) and
When I take a look into the terminal's output (I use server WEBRick on
Been playing with Ruby on Rails for awhile and decided to take a look

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.