473,416 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

how can I query for conditions on column_names

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_SCHEMA.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 1033
deepuv04
227 Expert 100+
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
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...
1
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...
7
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 ...
9
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...
2
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....
4
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...
2
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...
0
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...
5
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...
1
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....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.