Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Field Query

Author  Topic 

lane0618
Posting Yak Master

134 Posts

Posted - 2002-01-30 : 18:36:05
I have a table named SKU that has three fields- c1, c2, c3

I have a query named FIND that returns two of these field names c1 & c3.

I want to create a new query that looks at the SKU table and returns only the fields that are returned in the FIND query. I want this to be dynamic, so when the results of FIND change so do the fields of my new query.

Thanks for your help!
Lane



Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-01-30 : 18:54:16
Hi

That looks like a job for Dynamic SQL http://www.sqlteam.com/item.asp?ItemID=4599

But it sounds like your database isn't designed optimally. You shouldn't have fields like that containing the same sort of data, it sounds (from the limited info you have given) like you should maybe break that table up.

Look at dynamic sql for this problem, but if you post more info and a table structure there might be some things to make it better. It is always better to get the design right rather than code around a design problem with a dynamic sql hack.

Damian
Go to Top of Page

lane0618
Posting Yak Master

134 Posts

Posted - 2002-01-30 : 19:58:33
Thanks but...

First, As far as the database design, the SKU table has yes/no data in it that correlates to a list of features, so I can't implement that data into another table. (Hope that makes sense).

I checked out your article on dynamic SQL and I am confused on how to create the parameter in the first place. Could you show me what the stored procedure code would look like for my example? I feel like I'm missing something obvious, sorry for my confusion.

Thanks!
Lane




Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-01-30 : 20:12:34
No your design doesn't make sense.

Multiple yes/no fields are not good design. Instead, you should have something like a table of features, then a many-many table between the SKU and the features indicating which ones it has.

I can't show you want the code will look like because I don't know anything about your situation, you gave me this much to work with

quote:

I have a query named FIND that returns two of these field names c1 & c3.



Now I can not figure out too much from that. It's like me saying "I have a house, which way to the door ?"

If you get my meaning.

I am going to take a wild guess here...

Your end result is that you want to be able to pass in a list of features, and get a set of all the products that contain some or all of those features. How close is that ?

If the answer is yes, then I would definitely recommend a DB design change rather than a dynamic sql hack.

Hope that helps

Damian
Go to Top of Page
   

- Advertisement -