?
Solved

SQL 2008

Posted on 2011-02-25
5
Medium Priority
?
249 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:DBA2010
  • 3
5 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34983547

you need to join the tables

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

0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34983559
cast as order.orderno as varchar

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

Author Comment

by:DBA2010
ID: 34983702
why is that?
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34983768

To compare fields from two tables, they need to be linked in some way, in this case I'm using a join
0
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 34983875
try this.
select * 
  from [Order] o
  join [Invoice] i 
    on o.OrderNo like i.OrderNo+'%'

Open in new window

or
select * 
  from [Order] o
 where exists (select 1 from [Invoice] i where o.OrderNo like i.OrderNo+'%')

Open in new window

0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question