Solved

SQL 2008

Posted on 2011-02-25
5
239 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:ewangoya
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:ewangoya
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:ewangoya
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 40

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

776 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