SQL 2008

Posted on 2011-02-25
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 +'%')
Order.OrderNo = 1000
Invoice.OrderNo = 1000C
Is there another way to do that?

Question by:DBA2010
  • 3
LVL 32

Expert Comment

ID: 34983547

you need to join the tables

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

LVL 32

Expert Comment

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

Author Comment

ID: 34983702
why is that?
LVL 32

Expert Comment

ID: 34983768

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

Accepted Solution

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

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

Open in new window


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

Suggested Solutions

Title # Comments Views Activity
Updating ms sql with special characters 8 41
IN with @variable 5 25
Update in Sql 7 30
Filtered index 5 56
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now