Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where column in ( two + values here )

Status
Not open for further replies.

sramey00

Programmer
Jun 9, 2004
149
US
im trying to search a string a db gather the needed information and then query another db for the records that match the information. i can obtain the first set of data fine.
up to the print line works... looks like 1259,1333

however when i try to use that in the second select statement, i receive an error: Syntax error converting the varchar value '1259,1333' to a column of data type int.
my column is declared as type in and my variable is declared as type varchar. ive been trying to use the replace function to take out the quotes that are put onthe data. yet im having no luck. any suggestions?

Code:
declare @test varchar(255)
select @test = replace(substring(page_name, patindex('%255B%', page_name) + 4, len(page_name) - patindex('%255B%', page_name) - 8), '%252C', ',')
from crystallog
where log_time = '20:39:54'
and page_name like '%255B%'
--print @test

select * from salesrptd1.dbo.salesrep
where salesrep_nbr in (@test)



Mr. Steve

 
You will have to use a bit of dynamic SQL. Good luck!

Code:
DECLARE @sql nvarchar(1000)

SET @sql = 'select * from salesrptd1.dbo.salesrep
where salesrep_nbr in (' + @test + ')'

PRINT @sql
EXEC(@sql)


--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
ahh yes good ol'dynamic sql!

thanks for the push, i seemed to have forgotten that trick!

Mr. Steve

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top