Since I believe this should be a basic question I know this question has probably been asked, but I am unable to find it. I\'m probably about to earn my Peer Pressure badge,
This might me the most simple solution use like any
select *
from jobdetails
where job_no like any ('0711%', '0712%')
In Teradata this works fine.
Try this
select *
from jobdetails
where job_no between '0711' and '0713'
the only problem is that job '0713'
is going to be returned as well
so can use '07299999999999'
or just add and job_no <> '0713'
Dan zamir
As Jeremy Smith posted it, i'll recap, since I couldn't answer to that particular question of his.
select *
from jobdetails
where job_no like '071[1-2]%'
If you just need 0711%
and 0712%
you can also place a ranges within the brackets. For the NOT
keyword you could also use [^1-2]%
How about something like this?
declare @search table
(
searchString varchar(10)
)
-- add whatever criteria you want...
insert into @search select '0711%' union select '0712%'
select j.*
from jobdetails j
join @search s on j.job_no like s.searchString
You have the answer right there in your question. You cannot directly pass wildcard when using IN. However, you can use a sub-query.
Try this:
select *
from jobdetails
where job_no in (
select job_no
from jobdetails
where job_no like '0711%' or job_no like '0712%')
)
I know that this looks crazy, as you can just stick to using OR in your WHERE clause. why the subquery? How ever, the subquery approach will be useful when you have to match details from a different source.
Raj
I firstly added one off static table with ALL possibilities of my wildcard results (this company has a 4 character nvarchar code as their localities and they wildcard their locals) i.e. they may have 456? which would give them 456[1] to 456[Z] i.e 0-9 & a-z
I had to write a script to pull the current user (declare them) and pull the masks for the declared user.
Create some temporary tables just basic ones to rank the row numbers for this current user
loop through each result (YOUR Or this Or that etc...)
Insert into the test Table.
Here is the script I used:
Drop Table #UserMasks
Drop Table #TESTUserMasks
Create Table #TESTUserMasks (
[User] [Int] NOT NULL,
[Mask] [Nvarchar](10) NOT NULL)
Create Table #UserMasks (
[RN] [Int] NOT NULL,
[Mask] [Nvarchar](10) NOT NULL)
DECLARE @User INT
SET @User = 74054
Insert Into #UserMasks
select ROW_NUMBER() OVER ( PARTITION BY ProntoUserID ORDER BY Id DESC) AS RN,
REPLACE(mask,'?','') Mask
from dbo.Access_Masks
where prontouserid = @User
DECLARE @TopFlag INT
SET @TopFlag = 1
WHILE (@TopFlag <=(select COUNT(*) from #UserMasks))
BEGIN
Insert Into #TestUserMasks
select (@User),Code from dbo.MaskArrayLookupTable
where code like (select Mask + '%' from #UserMasks Where RN = @TopFlag)
SET @TopFlag = @TopFlag + 1
END
GO
select * from #TESTUserMasks