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)
 Parsing table with another tables information

Author  Topic 

jmpierce30
Starting Member

7 Posts

Posted - 2009-04-15 : 15:22:02

Good day,

I'm trying to accomplish a time parse and delete from a table based on paramaters that I am placing in another table.

Here is basically what I want to do

SELECT * FROM Table
WHERE Column1 LIKE '%' + (SELECT Column2 FROM Table2) + '%'

The subquery is returning multiple results and I'm not sure how to remedy this or what format I would use to accomplish the same thing but i need to be able to insert things that I want to be found in table two, and then run through the records on table one and see if i can find anything like that. :-)

thanks in advance for any help!



while (I != Understand)
{
KickMe.Hard;
}

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-04-15 : 15:31:12
is there any relationship between table and table2? and PK FK relationship or some other relationship

<><><><><><><><><><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

jmpierce30
Starting Member

7 Posts

Posted - 2009-04-15 : 15:33:15
There is no relationship between the two, what i'm trying to do is enter in words into a column on table2, and then search for titles on table 1 that contain the words on table 2 and then delete them out.

:-)

while (I != Understand)
{
KickMe.Hard;
}
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-04-15 : 15:40:39
you could do a cursor and loop through it


-- Declare the variables to store the values returned by FETCH.
DECLARE @Column2 VARCHAR(50)
DECLARE @Query VARCHAR(8000)
DECLARE jmpierce30_cursor CURSOR FOR
SELECT Column2
FROM dbo.Table

OPEN jmpierce30_cursor

-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.

FETCH NEXT FROM jmpierce30_cursor
INTO @Column2

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN

SET @Query = 'SELECT * FROM Table
WHERE Column1 LIKE %' + @Column2 + '%'

EXEC (@Query)

-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM jmpierce30_cursor
INTO @Column2
END

CLOSE jmpierce30_cursor
DEALLOCATE jmpierce30_cursor
GO

somethnig like dat
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-16 : 04:00:08
Try this too

SELECT t1.* FROM Table as t1 inner join table2 as t2
on t1.Column1 LIKE '%' + t2.Column2 + '%'


Madhivanan

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

- Advertisement -