dbTalk Databases Forums  

Need help with stored procedure.

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss Need help with stored procedure. in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Vanessa Lee
 
Posts: n/a

Default Need help with stored procedure. - 03-13-2005 , 09:30 PM






Hi,
I am using SQL Server 2000 on Windows 2000 server. Here is my problem:

@String = 'word1word2word3word4word5' - This value is passed to Stored
Procedure from the script.

Column1 in a table1 has many rows with "words" . One row in this column1
will have 'word3'. Notice that this 'word3' is contained in the @String.

I need to write a stored procedure SELECT statement that will return all
(Select *) values from all columns corresponding to a row containing
'word3'. (this 'word3' must be found in @String). 'word3' is the entire
value of the column. Somehow the search will have to be done on @String to
see if there is a match, and if there is a match, return values of all
columns corresponding to this row where the match is found.

It will have to be something like:

SELECT * FROM table1 WHERE @String has 'word3' in it.

I need help with the statement after the WHERE command.

Thank you for your help.
Vanessa



Reply With Quote
  #2  
Old   
Deepak Puri
 
Posts: n/a

Default Re: Need help with stored procedure. - 03-13-2005 , 11:12 PM






Hopefully, you posted this question to the SQL Server Programming group,
since it relates to SQL queries.

Will there always be just 1 column: 'column1' in table1, with the word
that is to be found - in that case, you could use charindex():

Quote:
SELECT * FROM table1
WHERE charindex(table1.column1, @String) > 0
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Reply With Quote
  #3  
Old   
Vanessa Lee
 
Posts: n/a

Default Re: Need help with stored procedure. - 03-14-2005 , 07:29 AM



You know, I need to give you a big credit. You are one of the most
intelligent people in the SQL newsgroups. Yes, I did crossposted the
question all over the newsgroups, because I doubted that people will
understand my question, but YOU DID! and the solution you show is very
smart. It works pretty well. I tried it. Your a smart man. I am pretty sure
you will get very far in whatever you do with your career. Thank you.

Vanessa

"Deepak Puri" <deepak_puri (AT) progressive (DOT) com> wrote

Quote:
Hopefully, you posted this question to the SQL Server Programming group,
since it relates to SQL queries.

Will there always be just 1 column: 'column1' in table1, with the word
that is to be found - in that case, you could use charindex():


SELECT * FROM table1
WHERE charindex(table1.column1, @String) > 0



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.