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)
 Basic Subquery Question

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2005-11-18 : 15:57:59
I have a feature on my site where I allow my users to save their search results against a table. I basically just save the SQL string to a table, allow the user to give it a name and then they can retrieve it later. Now I would like to allow users to be able to search against this saved search rather than against the entire database. My approach is something like this where (SELECT companyname, industry FROM TCompanies WHERE compid=13989) is the SQL string that was saved but it's not working.

SELECT *
FROM (SELECT companyname, industry FROM TCompanies WHERE compid=13989)
WHERE CompanyName LIKE '%American%'

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-19 : 00:12:38
Post some sample data and the result you want
What do you get when you run that query?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-20 : 01:45:18
Somthing like this..
you need to run the dynamic sql for that..

Declare @CompName Varchar(100)
Set @CompName = 'America'
Exec ('Select CompName,Industry From Tcompanies Where CompID = 13989 And CompanyName Like %' + @CompName + '%')

You can embedd this into some stored proc and display the records.. acc..

Hope this helps..

Complicated things can be done by simple thinking
Go to Top of Page
   

- Advertisement -