-1

I never work with views so im a bit newb to how they work and the purpose of a view. Anyway, I'm getting an error on a sp. I think its related to my view. Pretty sure the view is broke and need to rebuild it. At least logically that sounds like the issue to me. I don't know and I dont know how to rebuild it if thats the case.

Errors:

  • Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 16 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 18 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 3 [Batch Start Line 0] Invalid column name 'Brand'. Msg 4413, Level 16, State 1, Line 66 Could not use view or function 'OrderItemProduction_vw' because of binding errors. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 16 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 18 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 3 [Batch Start Line 0] Invalid column name 'Brand'. Msg 4413, Level 16, State 1, Line 89 Could not use view or function 'OrderItemProduction_vw' because of binding errors. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 16 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 18 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 3 [Batch Start Line 0] Invalid column name 'Brand'. Msg 4413, Level 16, State 1, Line 112 Could not use view or function 'OrderItemProduction_vw' because of binding errors. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 16 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 18 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 3 [Batch Start Line 0] Invalid column name 'Brand'. Msg 4413, Level 16, State 1, Line 135 Could not use view or function 'OrderItemProduction_vw' because of binding errors. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 16 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 18 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 3 [Batch Start Line 0] Invalid column name 'Brand'. Msg 4413, Level 16, State 1, Line 158 Could not use view or function 'OrderItemProduction_vw' because of binding errors.

SP:

    DECLARE
    -- Add the parameters for the stored procedure here
    @StatusType varchar(32) = 'Order', 
    @Filter varchar(32) = 'Bolingbrook',
    @Station varchar(32) = '',
    @AttrValue varchar(128) = ''
--AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    DECLARE @Date datetime
    SET @Date = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

    IF @StatusType = 'Order'
    BEGIN
        SELECT @Filter AS Filter, NULL AS DueDate, StatusSort, StatusDescription, 0 AS Total
        FROM [Status]
        WHERE StatusType = @StatusType
        UNION
        SELECT @Filter AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
        UNION
        SELECT @Filter AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, COUNT(i.OrderStatus) AS Total
        FROM (
            SELECT DISTINCT @Filter AS Facility, o.DueDate, s.StatusSort, s.StatusDescription
            FROM Orders o WITH (READUNCOMMITTED)
            CROSS JOIN Status s
            WHERE s.StatusType = @StatusType AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
        LEFT OUTER JOIN Orders i WITH (READUNCOMMITTED) ON i.OrderStatus = s.StatusDescription AND i.DueDate = s.DueDate AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR i.DueDate >= @Date)
        GROUP BY s.DueDate, s.StatusSort, s.StatusDescription
        UNION
        SELECT @Filter AS Filter, DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
        FROM Orders WITH (READUNCOMMITTED)
        WHERE ((DueDate < @Date AND OrderStatus NOT IN ('Shipped','Cancelled')) OR DueDate >= @Date)
        GROUP BY DueDate
        ORDER BY Filter, DueDate, StatusSort
    END
    IF @StatusType = 'Production'
    BEGIN
        IF @Station = ''
        BEGIN
            SELECT @Filter AS Filter, NULL AS DueDate, StatusSort, StatusDescription, 0 AS Total
            FROM [Status]
            WHERE StatusType = @StatusType+'_'+@Filter
            UNION
            SELECT @Filter AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
            UNION
            SELECT s.ProductGroup AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, SUM(ISNULL(i.ProductionQuantity,0)) AS Total--, COUNT(i.ProductionStatus) AS Total
            FROM (
                SELECT DISTINCT o.ProductGroup, o.DueDate, s.StatusSort, s.StatusDescription
                FROM OrderItemProduction_vw o WITH (READUNCOMMITTED)
                CROSS JOIN [Status] s
                WHERE s.StatusType = @StatusType+'_'+@Filter AND o.ProductGroup = @Filter AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
            LEFT OUTER JOIN OrderItemProduction_vw i WITH (READUNCOMMITTED) ON i.ProductGroup = @Filter AND i.ProductionStatus = s.StatusDescription AND i.DueDate = s.DueDate AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR (i.DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY s.ProductGroup, s.DueDate, s.StatusSort, s.StatusDescription
            UNION
            SELECT ProductGroup AS Filter, DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
            FROM OrderItemProduction_vw WITH (READUNCOMMITTED)
            WHERE ProductGroup = @Filter AND ((DueDate < @Date AND OrderStatus NOT IN ('Shipped','Cancelled')) OR (DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY ProductGroup, DueDate
            ORDER BY Filter, DueDate, StatusSort
        END
        ELSE IF @Station = 'UV'
        BEGIN
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, StatusSort, StatusDescription, 0 AS Total
            FROM [Status]
            WHERE StatusType = @StatusType+'_'+@Filter
            UNION
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
            UNION
            SELECT s.ProductGroup AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, SUM(ISNULL(i.ProductionQuantity,0)) AS Total--, COUNT(i.ProductionStatus) AS Total
            FROM (
                SELECT DISTINCT o.ProductGroup+' '+o.UV AS ProductGroup, o.DueDate, s.StatusSort, s.StatusDescription
                FROM OrderItemProduction_vw o WITH (READUNCOMMITTED)
                CROSS JOIN [Status] s
                WHERE s.StatusType = @StatusType+'_'+@Filter AND o.ProductGroup = @Filter AND o.UV = @AttrValue AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
            LEFT OUTER JOIN OrderItemProduction_vw i WITH (READUNCOMMITTED) ON i.ProductGroup = @Filter AND i.ProductionStatus = s.StatusDescription AND i.DueDate = s.DueDate AND i.UV = @AttrValue AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR (i.DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY s.ProductGroup, s.DueDate, s.StatusSort, s.StatusDescription
            UNION
            SELECT ProductGroup+' '+UV AS Filter, DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
            FROM OrderItemProduction_vw WITH (READUNCOMMITTED)
            WHERE ProductGroup = @Filter AND UV = @AttrValue AND ((DueDate < @Date AND OrderStatus NOT IN ('Shipped','Cancelled')) OR (DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY ProductGroup+' '+UV, DueDate
            ORDER BY Filter, DueDate, StatusSort
        END
        ELSE IF @Station = 'Diecut'
        BEGIN
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, StatusSort, StatusDescription, 0 AS Total
            FROM [Status]
            WHERE StatusType = @StatusType+'_'+@Filter
            UNION
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
            UNION
            SELECT s.ProductGroup AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, SUM(ISNULL(i.ProductionQuantity,0)) AS Total--, COUNT(i.ProductionStatus) AS Total
            FROM (
                SELECT DISTINCT o.ProductGroup+' '+o.PaperTrim AS ProductGroup, o.DueDate, s.StatusSort, s.StatusDescription
                FROM OrderItemProduction_vw o WITH (READUNCOMMITTED)
                CROSS JOIN [Status] s
                WHERE s.StatusType = @StatusType+'_'+@Filter AND o.ProductGroup = @Filter AND o.PaperTrim = @AttrValue AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
            LEFT OUTER JOIN OrderItemProduction_vw i WITH (READUNCOMMITTED) ON i.ProductGroup = @Filter AND i.ProductionStatus = s.StatusDescription AND i.DueDate = s.DueDate AND i.PaperTrim = @AttrValue AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR (i.DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY s.ProductGroup, s.DueDate, s.StatusSort, s.StatusDescription
            UNION
            SELECT ProductGroup+' '+PaperTrim AS Filter, DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
            FROM OrderItemProduction_vw WITH (READUNCOMMITTED)
            WHERE ProductGroup = @Filter AND PaperTrim = @AttrValue AND ((DueDate < @Date AND OrderStatus NOT IN ('Shipped','Cancelled')) OR (DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY ProductGroup+' '+PaperTrim, DueDate
            ORDER BY Filter, DueDate, StatusSort
        END
        ELSE IF @Station = 'Print'
        BEGIN
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, StatusSort, StatusDescription, 0 AS Total
            FROM [Status]
            WHERE StatusType = @StatusType+'_'+@Filter
            UNION
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
            UNION
            SELECT s.ProductGroup AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, SUM(ISNULL(i.ProductionQuantity,0)) AS Total--, COUNT(i.ProductionStatus) AS Total
            FROM (
                SELECT DISTINCT o.ProductGroup+' '+o.Substrate AS ProductGroup, o.DueDate, s.StatusSort, s.StatusDescription
                FROM OrderItemProduction_vw o WITH (READUNCOMMITTED)
                CROSS JOIN [Status] s
                WHERE s.StatusType = @StatusType+'_'+@Filter AND o.ProductGroup = @Filter AND o.Substrate = @AttrValue AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
            LEFT OUTER JOIN OrderItemProduction_vw i WITH (READUNCOMMITTED) ON i.ProductGroup = @Filter AND i.ProductionStatus = s.StatusDescription AND i.DueDate = s.DueDate AND i.Substrate = @AttrValue AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR (i.DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY s.ProductGroup, s.DueDate, s.StatusSort, s.StatusDescription
            UNION
            SELECT ProductGroup+' '+Substrate AS Filter, DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
            FROM OrderItemProduction_vw WITH (READUNCOMMITTED)
            WHERE ProductGroup = @Filter AND Substrate = @AttrValue AND ((DueDate < @Date AND OrderStatus NOT IN ('Shipped','Cancelled')) OR (DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY ProductGroup+' '+Substrate, DueDate
            ORDER BY Filter, DueDate, StatusSort
        END
        ELSE IF @Station = 'Press'
        BEGIN
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, StatusSort, StatusDescription, 0 AS Total
            FROM [Status]
            WHERE StatusType = @StatusType+'_'+@Filter
            UNION
            SELECT @Filter+' '+@AttrValue AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
            UNION
            SELECT s.ProductGroup AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, SUM(ISNULL(i.ProductionQuantity,0)) AS Total--, COUNT(i.ProductionStatus) AS Total
            FROM (
                SELECT DISTINCT o.ProductGroup+' '+o.Press AS ProductGroup, o.DueDate, s.StatusSort, s.StatusDescription
                FROM OrderItemProduction_vw o WITH (READUNCOMMITTED)
                CROSS JOIN [Status] s
                WHERE s.StatusType = @StatusType+'_'+@Filter AND o.ProductGroup = @Filter AND o.Press = @AttrValue AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
            LEFT OUTER JOIN OrderItemProduction_vw i WITH (READUNCOMMITTED) ON i.ProductGroup = @Filter AND i.ProductionStatus = s.StatusDescription AND i.DueDate = s.DueDate AND i.Press = @AttrValue AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR (i.DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY s.ProductGroup, s.DueDate, s.StatusSort, s.StatusDescription
            UNION
            SELECT ProductGroup+' '+Press AS Filter, DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
            FROM OrderItemProduction_vw WITH (READUNCOMMITTED)
            WHERE ProductGroup = @Filter AND Press = @AttrValue AND ((DueDate < @Date AND OrderStatus NOT IN ('Shipped','Cancelled')) OR (DueDate >= @Date AND OrderStatus NOT IN ('Cancelled')))
            GROUP BY ProductGroup+' '+Press, DueDate
            ORDER BY Filter, DueDate, StatusSort
        END
    END
    IF @StatusType = 'ShipMethod'
    BEGIN
        SELECT @Filter AS Filter, NULL AS DueDate, StatusSort, StatusDescription, 0 AS Total
        FROM [Status]
        WHERE StatusType = @StatusType+'_'+@Filter
        UNION
        SELECT @Filter AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
        UNION
        SELECT @Filter AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, COUNT(i.OrderStatus) AS Total
        FROM (
            SELECT DISTINCT @Filter AS Facility, o.DueDate, s.StatusSort, s.StatusDescription
            FROM Orders o WITH (READUNCOMMITTED)
            CROSS JOIN [Status] s
            WHERE s.StatusType = @StatusType AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
        LEFT OUTER JOIN Orders i WITH (READUNCOMMITTED) ON i.shipMethod = s.StatusDescription AND i.DueDate = s.DueDate AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR i.DueDate >= @Date)
        GROUP BY s.DueDate, s.StatusSort, s.StatusDescription
        UNION
        SELECT @Filter AS Filter, DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
        FROM Orders WITH (READUNCOMMITTED)
        WHERE ((DueDate < @Date AND OrderStatus NOT IN ('Shipped','Cancelled')) OR DueDate >= @Date)
        GROUP BY DueDate
        ORDER BY Filter, DueDate, StatusSort
    END
    IF @StatusType = 'Packaging'
    BEGIN
        SELECT @Filter AS Filter, NULL AS DueDate, s.StatusSort, s.StatusDescription, 0 AS Total
        FROM [Status] s
        --INNER JOIN Packaging p ON p.Facility = @Filter AND p.PackagingCode = s.StatusDescription
        WHERE StatusType = @StatusType+'_'+@Filter
        UNION
        SELECT @Filter AS Filter, NULL AS DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, 0 AS Total
        UNION
        SELECT @Filter AS Filter, s.DueDate, s.StatusSort, s.StatusDescription, COUNT(i.Packaging) AS Total
        FROM (
            SELECT DISTINCT @Filter AS Facility, o.DueDate, s.StatusSort, s.StatusDescription
            FROM Orders o WITH (READUNCOMMITTED)
            CROSS JOIN [Status] s
            WHERE s.StatusType = @StatusType AND ((o.DueDate < @Date AND o.OrderStatus NOT IN ('Shipped','Cancelled')) OR o.DueDate >= @Date)) s
        INNER JOIN Packaging p ON p.PackagingCode = s.StatusDescription
        LEFT OUTER JOIN Orders i WITH (READUNCOMMITTED) ON i.Packaging = s.StatusDescription AND i.DueDate = s.DueDate AND ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR i.DueDate >= @Date)
        GROUP BY s.DueDate, s.StatusSort, s.StatusDescription
        UNION
        SELECT @Filter AS Filter, i.DueDate, 999.0000 AS StatusSort, 'Total' AS StatusDescription, COUNT(*) AS Total
        FROM Orders i WITH (READUNCOMMITTED)
        INNER JOIN Packaging p ON p.PackagingCode = i.Packaging
        WHERE ((i.DueDate < @Date AND i.OrderStatus NOT IN ('Shipped','Cancelled')) OR i.DueDate >= @Date)
        GROUP BY i.DueDate
        ORDER BY Filter, DueDate, StatusSort
    END
END

Here is the view its self:

SELECT TOP (1000) [OrderId]
  ,[version]
  ,[OrderNo]
  ,[OriginalOrderNo]
  ,[RedoType]
  ,[CustomerNo]
  ,[OrderDate]
  ,[OrderDateString]
  ,[RequestedDueDate]
  ,[RequestedDueDateString]
  ,[Brand]
  ,[RushService]
  ,[ShipMethod]
  ,[ShippingAttention]
  ,[ShippingAddressee]
  ,[ShippingAddressLine1]
  ,[ShippingAddressLine2]
  ,[ShippingCity]
  ,[ShippingState]
  ,[ShippingZip]
  ,[ShippingCountry]
  ,[ShippingPhone]
  ,[OrderNote]
  ,[ItemNote]
  ,[DateOrdered]
  ,[DueDate]
  ,[Items]
  ,[TotalItems]
  ,[Packaging]
  ,[RandomNumber]
  ,[ShipDate]
  ,[ShippingNotes]
  ,[DateShipped]
  ,[Carrier]
  ,[ShipService]
  ,[Tracking]
  ,[Units]
  ,[Weight]
  ,[RejectCode]
  ,[RejectReason]
  ,[OrderReceived]
  ,[OrderStatus]
  ,[OrderStatusDate]
  ,[TransmissionDate]
  ,[TransmissionResponse]
  ,[Staging]
  ,[ItemId]
  ,[LineNo]
  ,[ItemNo]
  ,[SKU]
  ,[Description]
  ,[PaperType]
  ,[PaperTrim]
  ,[Pages]
  ,[Quantity]
  ,[unitPrice]
  ,[ProductType]
  ,[ItemNum]
  ,[ItemStatus]
  ,[ItemStatusDate]
  ,[Orientation]
  ,[Substrate]
  ,[SubstrateWeight]
  ,[SubstrateColor]
  ,[Inks]
  ,[UV]
  ,[SKUDescription]
  ,[ProductGroup]
  ,[Facility]
  ,[ProductName]
  ,[Size]
  ,[Cost]
  ,[Price]
  ,[Retail]
  ,[UnitWeight]
  ,[ProductCategory]
  ,[ProductSKUCode]
  ,[Permutations]
  ,[Press]
  ,[TicketTemplate]
  ,[isActive]
  ,[SubItemId]
  ,[SubLineNo]
  ,[SubItemNo]
  ,[SubSKU]
  ,[SubDescription]
  ,[SubPaperType]
  ,[SubPaperTrim]
  ,[SubPages]
  ,[SubQuantity]
  ,[SubunitPrice]
  ,[SubProductType]
  ,[SubItemNum]
  ,[SubItemStatus]
  ,[SubItemStatusDate]
  ,[SubOrientation]
  ,[SubSubstrate]
  ,[SubSubstrateWeight]
  ,[SubSubstrateColor]
  ,[SubInks]
  ,[SubUV]
  ,[SubSKUDescription]
  ,[SubProductGroup]
  ,[SubFacility]
  ,[SubProductName]
  ,[SubSize]
  ,[SubCost]
  ,[SubPrice]
  ,[SubRetail]
  ,[SubUnitWeight]
  ,[SubProductCategory]
  ,[SubProductSKUCode]
  ,[SubPermutations]
  ,[SubPress]
  ,[SubTicketTemplate]
  ,[SubisActive]

FROM [Collage].[dbo].[OrderItems_vw]

Im getting errors when I try to query the view. So I think this is linked to the root cause:

Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 16 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 18 [Batch Start Line 0] Invalid column name 'Brand'. Msg 207, Level 16, State 1, Procedure OrderItems_vw, Line 3 [Batch Start Line 0] Invalid column name 'Brand'. Msg 4413, Level 16, State 1, Line 118 Could not use view or function 'Collage.dbo.OrderItems_vw' because of binding errors.

mholmes
  • 177
  • 2
  • 14
  • Please consider putting that mess of an error message into a readable format. Thank you. – Thom A Oct 17 '19 at 16:07
  • Also, you start off my stating you are using a `VIEW`, but then you've tagged and define what appear to be a Stored Procedure. The two are very different object types. What are you really working with here? A `VIEW` can't be parametrised, so I doubt that is what you are really using. – Thom A Oct 17 '19 at 16:08
  • 1
    Your errors are referring to an "illegal column name" `Brand`, yet I can't find the word "Brand" anywhere in the code you posted. – daShier Oct 17 '19 at 16:12
  • Right thats what i thought too but Then I seen there is a view being sed. The View uses Brand. I think it needs to be rebuilt as suggested below – mholmes Oct 17 '19 at 16:33
  • You need to read [this](https://www.sentryone.com/blog/aaronbertrand/bad-habits-nolock-everywhere) before you continue splattering nolocks all over the place. Also, don't be scared to use a little white space in your code so you can actually read it. – Sean Lange Oct 17 '19 at 16:44
  • This is not my code I'm just working with it. Dont assume anyone's code on here was originally written by them. Most of us just inherit it. I'm also not a DBA. – mholmes Oct 17 '19 at 16:50

1 Answers1

1

Please see this for the related answer. Your underlying table on the view in question was modified and you need to recompile the view using sp_refreshview.

Sean Brookins
  • 574
  • 4
  • 12
  • I tried to refresh the view using "exec sp_refreshview @viewname='dbo.OrderItems_vw'" but still gives error on Brand. I don't know where this i coming from. If I knew what table was missing the column id just add it – mholmes Oct 17 '19 at 16:46
  • Hi @mholmes, please check the view definition and ensure that it isn't trying to select the column brands from the underlying table. If the underlying table was changed, and now a column name can't be found, the presumption would be that the table modification was to rename or remove that column... Right click the view in SSMS and script a "alter" statement and see if anything turns red, or if it's selecting [brand] somewhere. – Sean Brookins Oct 17 '19 at 17:25
  • You are correct Sean. I found it. It was missing in the Orders table: dbo.SKU AS k ON k.SKU = i.SKU AND k.Brand = o.Brand LEFT OUTER JOIN dbo.OrderItems AS si ON si.OrderId = i.OrderId AND si.ItemNo = i.ItemNo AND si.[LineNo] = i.[LineNo] + 1 LEFT OUTER JOIN dbo.SKU AS sk ON sk.SKU = si.SKU AND sk.Brand = o.Brand – mholmes Oct 17 '19 at 17:31