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)
 Dynamic Query

Author  Topic 

cfreeman
Starting Member

2 Posts

Posted - 2010-03-17 : 15:52:52
I am far from a DBA or SQL developer but I have a requirement that I need to complete.

In my database, I have a field that stores field names from another table in a pipe delimited varchar.

"field1|field2|field3|field4"

and a value required for each field

"Value1|Value2|Value3|Value4"

I need to read those values in break them apart and build a query to another table to get the requested result.

"SELECT NOTE From TABLENAME WHERE FIELD1 = VALUE1 and FIELD2 = VALUE2 AND FIELD3 = VALUE3"

Can this be done through a Stored Procedure or any other method, if so can someone point me in the right direction?

Thanks in advance.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-17 : 16:06:59
I think this an idea of the devil
But if you really want do to some stuff like that you have to go with dynamic sql.
See here:
http://www.sommarskog.se/dynamic_sql.html


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

cfreeman
Starting Member

2 Posts

Posted - 2010-03-17 : 16:19:55
I am not sure I have much choice based on the requirement from the client.

The user has to be able to add fields (of their choice) and values ( of thier choice to return a note based on those fields and values in another table.

IE.. They specify a temp of 80 degrees, a wind_direction SE and a speed 20. I run a query (view) that returns a set of data then based on what the user specified and what is returned from the view, I find the note stored in a seperate table (Join the note with the data based on the fields and values). Sigh, this is going to give me more gray hair.
Go to Top of Page
   

- Advertisement -