Solved

SQL 2008

Posted on 2011-02-25
5
241 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

713 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