Link to home
Start Free TrialLog in
Avatar of DBA2010
DBA2010

asked on

SQL 2008

I tried to use a where statment on my code but its not working

select * from Tablename
Where  Order.OrderNo like (Invoice.OrderNo +'%')
Example:
Order.OrderNo = 1000
Invoice.OrderNo = 1000C
Is there another way to do that?

Thanks
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image


you need to join the tables

select *
from Order
inner join invoice on charindex(Order.orderNo, Invoice.OrderNo, 1) > 0

cast as order.orderno as varchar

select *
from Order
inner join invoice on charindex(cast(Order.orderNo as varchar), Invoice.OrderNo, 1) > 0
Avatar of DBA2010
DBA2010

ASKER

why is that?

To compare fields from two tables, they need to be linked in some way, in this case I'm using a join
ASKER CERTIFIED SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial