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)
 Problem with a simple query -constructing wildcard

Author  Topic 

Ravi0435
Starting Member

47 Posts

Posted - 2009-03-12 : 16:02:37

Hi:
I want to run a simple query

Select * From Member_Detail
Where group_number like ('00491%')

But i am in a process of something where-in i will need the query to work when i re-write it in the following way, i tried several methods and it looks simple but it does not work:

None of the following work:

------> 1

SET QUOTED_IDENTIFIER OFF
GO
Select * From Member_Detail
Where group_number like ("'"+ (substring('00491F001',1,5)+ '%')+"'")

-------> 2
SET QUOTED_IDENTIFIER OFF
GO
Declare @temp Varchar(10)
Set @temp = ("'"+ (substring('00491F001',1,5)+ '%')+"'")

Select * From Member_Detail
Where group_number like @temp

--------> 3
SET QUOTED_IDENTIFIER OFF
GO
Declare @temp Varchar(10)
Set @temp = "('"+ (substring('00491F001',1,5)+ '%')+"')"

Select * From Member_Detail
Where group_number like @temp
------


Any suggestions would be appreciated.


thanks,
R



Nothing much that i can do..!!

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-12 : 16:47:27
what exactly are you looking for?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-12 : 16:48:42
SET QUOTED_IDENTIFIER OFF
GO
Select * From Member_Detail
Where group_number like substring('00491F001', 1, 5) + '%'

-------> 2
SET QUOTED_IDENTIFIER OFF
GO
Declare @temp Varchar(10)
Set @temp = substring('00491F001', 1, 5) + '%'

Select * From Member_Detail
Where group_number like @temp

--------> 3
SET QUOTED_IDENTIFIER OFF
GO
Declare @temp Varchar(10)
Set @temp = substring('00491F001', 1, 5) + '%'

Select * From Member_Detail
Where group_number like @temp


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Ravi0435
Starting Member

47 Posts

Posted - 2009-03-13 : 09:41:58
Thanks "PESO"....it worked ...i wonder how did i miss that...i tried all the possibilities even constructed parenthesis before and after the single quotes...thanks again.

still wondering whats the difference?

like ("'"+ (substring('00491F001',1,5)+ '%')+"'")
and
like substring('00491F001', 1, 5) + '%'


or for that matter:


like (substring('00491F001',1,5)+ '%')
and
like substring('00491F001', 1, 5) + '%'


Only if you have time-answer, if not its fine as long as it works..!!
thanks again.


thanks,
R

Nothing much that i can do..!!
Go to Top of Page
   

- Advertisement -