473,706 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can I query for conditions on column_names

1 New Member
i have my database with the columns as follows:

keyword, part1_d1, part1_d2 ........ part1_d25, part2_d26, ......part2_d34

FYI: d1 through d34 are documents..

how can I give a query to obtain columns with column_name like '%part1%'; as below

keyword, part1_d1, part1_d2, ........ part1_d25

I tried the query:

select (Select COLUMN_NAME From INFORMATION_SCH EMA.COLUMNS where COLumn_NAME like '%part1%') , keyword from sample

But it dint work...

Please let me know what to do?
Aug 13 '10 #1
1 1047
deepuv04
227 Recognized Expert New Member
hi,
I think you are trying to get the column names dynamically. if that is the requirement... you need to build the query dynamically and execute the query string.

Try the following


Expand|Select|Wrap|Line Numbers
  1. DECLARE @STR VARCHAR(MAX)
  2. SET @Str = 'SELECT '
  3.  
  4. SELECT    @Str = @Str + Column_Name + ',' FROM Information_Schema.Columns
  5. WHERE    TABLE_Name = 'Table_Name' AND 
  6.         Column_Name like '%cOLUMN_Name%'
  7.  
  8.  
  9. SELECT @Str = SUBSTRING(@Str,0,len(@Str)) + ' FROM Table_Name' 
  10.  
  11. SELECT @Str
  12.  
  13. EXEC (@Str)
Aug 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1727
by: ben | last post by:
I have been using a nasty combination of php and mysql to generate a narrow down by attribute bar as seen on the likes of shopping.com. For example a user could select 4X Zoom to narrow down a selection of digital cameras. The current method I use is to loop though each one of the attributes and their values and run a separate query of each attribute value: for($i=0; $i < attribute_count; $i++) {
1
3454
by: Ryan Govostes | last post by:
Eh, I was wondering if anyone could help me with a SQL query problem I'm having. I'm a complete newbie to SQL and MySQL, so any help would be greatly appreciated. I am using PHP to allow users to submit ISBNs, prices, and item conditions into a MySQL database. The table the values are inserted into is declared with CREATE TABLE prices (isbn VARCHAR(10), price FLOAT UNSIGNED, conditions VARCHAR(5))
7
1684
by: Jim | last post by:
I need help on a query. There is a common titles database for several radio stations Some titles are enabled and some are not enabled for each station. Example of some tables: Titles Stations Station_Titles ------ -------- ------------- id id Station_ID Title StationName Title_ID
9
3402
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in a triangle. Like this member A -> B->C A give his appartment to B. B gives his appartment to C and finally C gives his appartment to A Soo my query looks for matching parameters like rooms, location, size
2
1938
by: Justin Koivisto | last post by:
Firstly, I want to thank all that have helped me out with getting grips on Access each time I've had questions. This has got to be one of the most helpful groups that I've posted to over the years. Now my problem... I have a listbox that I want to use to fill in the where clause of a query. I've been able to create a string holding the necessary WHERE clause without many problems. However, I cannot seem to reference the string inside...
4
1490
by: ime | last post by:
Hi to all. I'm making a web application in which users enter text for a person's name, last name, sex, etc. But user doesn't have to populate all text boxes, so I don't know how to make query without these conditions (for example if I have an empty string for a name) . I've got 9 text boxes, so I can't write all combinations - it's to many of them. Thanks a lot
2
1512
by: Jeff Gardner | last post by:
Greetings: I am attempting to split an input string using the str_word_count function to return multiple single word query variables. I can create an array based on $search=(str_word_count($search, 1, '0123456789')); (I want words and/or numbers). I can extract named variables from the resulting array via $search=extract($search, EXTR_PREFIX_ALL, search); and then call each variable by
0
2447
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in the whole. I really need MySQL wizz to give me a hand (and maybe refer me to books to get me to the wizz level myself). First off, english is a second language to me and sometimes my sentences might be a little awkward. Please forgive me. Mon...
5
2088
by: Samik2003 | last post by:
Hello, The problem is my query is not extracting the correct xml data from the database : Is there something which I am missing?? ANy help would be appriciated. Thanks, Sam. THis is the query which I am using to extract :
1
506
by: sliverdigger | last post by:
Greg Russell wrote: way. You can keep track of successive posts to iteratively build up and tentatively display a query statement, and then "submit" the finished query it when it looks right. You would need a form with multiple, carefully-named submit buttons to do that. Keep three buffers to append to: 1) chosen column names
0
8781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8696
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9285
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7906
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6614
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.