balikian Posted May 17, 2007 Share Posted May 17, 2007 I've got one table with with an compID, say "12345". I need to query another table which has a compCode with values based on the compID of the other table, so something like:12345_112345_212345_312345_4So I want to do something like:select * from TABLE where compCode like '(select compID from FIRSTTABLE where ID = '99999')%'But this doesn't work. Basically, I want to add a wildcard (%) to the end of a subselect. Is this possible? I've dug through all my books and can't find it. I'm fairly new to SQL. So there must be another way to do this. Thanks.scottp.s. this is my first time posting to this forum and one dealing with SQL, so hopefully I've explained what I am doing properly. Link to comment Share on other sites More sharing options...
aspnetguy Posted May 17, 2007 Share Posted May 17, 2007 Are you using MySql? Link to comment Share on other sites More sharing options...
aspnetguy Posted May 17, 2007 Share Posted May 17, 2007 ok try this select * from TABLE where compCode like (select compID from FIRSTTABLE where ID = '99999') + '%' This works in SQL Server Link to comment Share on other sites More sharing options...
balikian Posted May 17, 2007 Author Share Posted May 17, 2007 ahhhh + I was trying .'%' Totally worked. thanks. I'm using SQL Server 2005, BTW. thanks again! Link to comment Share on other sites More sharing options...
aspnetguy Posted May 17, 2007 Share Posted May 17, 2007 no problem, glad to help Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.