SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to move not like string into table??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

yeung_lcd
Starting Member

5 Posts

Posted - 12/04/2012 :  22:14:42  Show Profile  Reply with Quote
Say I have a sql query like this:

Declare @table1 TABLE(id INT, field1 VARCHAR(100))
INSERT INTO @table1
SELECT 1,'Apple Juice'
UNION ALL SELECT 2,'Orange Juice'
UNION ALL SELECT 3,'Coffee and tea'
UNION ALL SELECT 4,'randam text...'
UNION ALL SELECT 5,'I eat an apple everyday'

Select * from @table1
	where field1 not like '%apple%' and field1 not like '%orange%'


Now I want to put the hard code values "apple" and "orange" into a table so that I can update it without modifying SP or Query string in asp file.

How can I do it?

Thanks!

khtan
In (Som, Ni, Yak)

Singapore
17681 Posts

Posted - 12/04/2012 :  22:23:24  Show Profile  Reply with Quote
how about create a view for it ?


KH
Time is always against us

Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/05/2012 :  06:58:42  Show Profile  Reply with Quote
You can put the search terms into a table and join to that table - but you will always be querying for the terms that table. Is that what you really want?

Do you get the search terms from the asp.net side? If you are, are you sending those search terms to a stored proc? Give a bit more detail on what you are trying to do.
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 12/05/2012 :  08:20:56  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
create table SearchTerms
(
s varchar(20)
)
go
insert SearchTerms select 'apple'
insert SearchTerms select 'orange'
go
select t1.*
from @table1 t1
left join SearchTerms s
on t1.field1 like '%' + s.s + '%'
where s.s is null


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

yeung_lcd
Starting Member

5 Posts

Posted - 12/05/2012 :  21:31:57  Show Profile  Reply with Quote
quote:
Originally posted by sunitabeck



In fact I am working on a classic asp file... the query string is in the file and one user want to add some filters to the result (not parameter).

The user may update filter terms later on so I am looking for some shortcuts to do it.


quote:
Originally posted by nigelrivett


thx, I will try it :)

Edited by - yeung_lcd on 12/05/2012 21:32:45
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000