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 2005 Forums
 Transact-SQL (2005)
 string

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-03-24 : 12:30:54
Hi,
I have a string as follows:

"not" OR "hello you" AND NOT "office" OR "outside
home" AND NOT "inside house" OR "maybe inside"

How is it possible to pull out the words separately as follows please?

@NotList = "hello you" OR "office" OR "inside house"

@IncludeList = "outside
home" OR "maybe inside"

Thanks

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-24 : 13:56:18
maybe this, but of course it depends what you want to do..there might be a better way of doing what you are trying to do if you tell us your design approach and what you are trying to accomplish

DECLARE @NotList NVARCHAR(MAX)
DECLARE @IncludeList NVARCHAR(MAX)
SET @NotList = '"hello you" OR "office" OR "inside house"'
PRINT @NotList
SET @IncludeList = '"outside home" OR "maybe inside"'
PRINT @IncludeList
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2009-03-24 : 16:47:22
Look into passing a dynamic where clause. You are making much more work for yourself using the format you have chosen.

Try to simply pass two variables, 1 for your include list and 1 for your not include.

so :


Declare @Include varchar(500),@NotInclude Varchar(500)

set @Include = '''Outside Home'',''maybe insude'''
set @NotInclude = '''hello you'',''office'',''inside house'''
Print @Include
Print @NotInclude

declare @MyStr varchar(2000)
set @MyStr = '
select *
from
MYTable a
where
a.MyCol in ( ' + @Include + ' )
and Not a.MyCol in ( ' + @NotInclude + ' )'

exec (@Mystr)



Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-03-24 : 17:43:14
Hello,
I think you mis-understood...
The text is being built dynamically and it changes.
The above is one of the examples of a sample string.
So, do you know how to go through a string and separate the NOT words so that I will have:

@NotList
@IncludeList

?
Thanks
Go to Top of Page
   

- Advertisement -