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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:05:26+00:00 2026-06-10T10:05:26+00:00

If I have this table TableABC and it has some fields/columns, rather say it

  • 0

If I have this table TableABC and it has some fields/columns, rather say it has many fields/columns col1, col2, col3..... say upto 10 or 20, the count doesn’t matter right now.
The point is, I wanna know, if we ask a user for input, say @input varchar(max) or something like this, what I wanna know is that..

How can I select a row, if this input occurs in any column in that row, I mean the row would be selected if col1=@input also if col2=@input and so on..

Now as I said the count of column doesn’t matter, what matters is we don’t know ahead of time the columns so that we may do something like

where
col1 = @input
or
col2 = @input

we can’t do that. I got as far as getting the names of column from table by say

SELECT [name] FROM sys.Columns WHERE [Object_id]=Object_id(N'TableABC')

This would give us names of col in the required table, now I don’t know what can we do with them, or is this even useful in the scenario I am describing? So, what’s the solution?

Lastly, in case someone might ask, where am I gonna use it, or what’s my requirement or something, let me clear its not for (at least as of now!) practical implementation, I just wanna know if its possible, and if so, how? I hope I made myself clear.

  • 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-10T10:05:27+00:00Added an answer on June 10, 2026 at 10:05 am

    You can use cursor to iterate through column names as you suggested and then build dynamic query, later exec it, something like this:

    DECLARE @Expression varchar(max)
    DECLARE @ColumnName varchar(max)
    SELECT @Expression = 'WHERE '
    
    DECLARE db_cursor CURSOR FOR SELECT [name] FROM sys.Columns WHERE [Object_id]=Object_id(N'TableABC')
    OPEN db_cursor   
    FETCH NEXT FROM db_cursor INTO @ColumnName   
    
    WHILE @@FETCH_STATUS = 0   
    BEGIN
        SELECT @Expression = @Expression + @ColumnName + ' = ' + @input + ' AND '
    
        FETCH NEXT FROM db_cursor INTO @ColumnName   
    END 
    
    CLOSE db_cursor   
    DEALLOCATE db_cursor
    
    SELECT @Expression
    -- EXEC(@Expression) etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a table ABC and table XYZ. Columns of ABC-->col1 col2 col3
Given a table ABC with columns Col1, Col2 and Col3 it is possible to
I have a table: abc_test with columns n_num, k_str. This query doesnt work: select
(Note: this is for MS SQL Server) Say you have a table ABC with
I have this table where I can generate dynamic rows (which has input <type=text
I have this table with some styled tds (I put screenshot because the content
I have this table in an Oracle DB which has a primary key defined
I have this table in some code; <table> <tr><td align=left>One</td><td align=center>Two</td><td align=right>Three</td> <tr><td align=left>One</td><td
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this table: UNIQUE_ID | WINNER_ID | FINALIST_ID ________1 | ________1 | __________2

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.