troubleshooting Question

TSQL : Select/Join works fine until I save it as a view?

Avatar of ClowWater
ClowWaterFlag for United States of America asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
3 Comments1 Solution459 ViewsLast Modified:
I have this view that I'm building (see below)...and in SSMS I can just highlight and run the 'select' part without errors, but if I execute this alter statement and then run a simple select of the view it errors out.  The error has to do with the "long" join line.

Code:

ALTER view [dbo].[vdvsalesorderline_cws] as

select
      a.sokey,a.trandate,ISNULL(a.chngorddate,a.TranDate) AS ChangeOrderDate,
      aj.costperfoot*c.qtyord
from tsosalesorder a
      left join tsosoline b
            left join timitem d
                  left join tLCcosts_cws aj on cast(substring(d.itemid,2,2) as int)=cast(aj.pipesize as int) and substring(d.itemid,8,1)='8' and d.userfld2='Y' and left(d.itemid,1) in ('1','2','3','4','5','6','7','8','0')
            on b.itemkey=d.itemkey
      on a.sokey=b.sokey

GO

** so if I highlight the 'select' code it runs just fine.  If I execute this code and it modifies the view and run a simple "select * from vdvsalesorderline_cws" it errors out with the error stating it cannot convert "ff" to an int...which I understand and that is why I had to put so many "and" statements on the join so that it wouldn't try to convert the rows that may have bad "pipesize" data.

I guess my question is why does the select alone work but it doesn't work as a view.  Does the execution act differently when running a select from a view?

This one is really puzzling me...any insight is GREATLY appreciated.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros