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)
 Select using wild card

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2010-03-16 : 13:49:38
Have following query:


select     convert(char(10), i.NEWDATE, 101) as Transdate,
i.TicketNo as TicketNo,
i.Tank as Tank,
p.petroEXcode as PetroExCode,
cast(sum(i.gross) as decimal(15, 2)) AS Gross,
cast(sum(i.net) as decimal(15,2)) as Net,
SUM(CASE WHEN i.mode = 'J' and p.petroEXcode = 'Y2' THEN convert(decimal(15,2),i.gross) ELSE convert(decimal(15,2),i.gross) * 42 END) as Gross,
SUM(CASE WHEN i.mode = 'J' and p.petroEXcode = 'Y2'THEN convert(decimal(15,2),i.net) ELSE convert(decimal(15,2),i.net) * 42 END) as Net
from [VESPTP6000-1].TP6000.dbo.Product as p
inner join [VESPTP6000-1].TP6000.dbo.TankArchive as t on t.basecode = p.base
inner join [VESPTP6000-1].TP6000.dbo.Inventory as i on (i.tank = t.tank and
i.period = t.period)
where (@Petroex IS null or p.petroEXcode = @Petroex or p.petroEXcode like replace(@Petroex,'*','%')) and
i.TicketNo <> ' ' and
i.Carrier <> ' ' and
i.Type = '4' and
(@DateFrom IS Null or i.NEWDATE >= @DateFrom) and
(@DateTo IS Null or i.NEWDATE < dateadd(day, 1, @DateTo))
group by i.NEWDATE,
i.TicketNo,
i.Tank,
p.PetroEXCode


The issue I have is following:

Value passed for @Petroex can be Null or a value (exampleK32) or wild card (example K*)

The result of my query does not seem to work if I pass in a wild card. If I pass K32 I get records but not on K*. Any ideas?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-16 : 14:06:01
I have tested it.
It works for me.
Are you sure there are any asterixes in @Petroex?

How looks the declare for @Petroex?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -