Question : SQL View problems with Cast and display on a Web page

I have a web app using ASP and Javascript that is linked to a SQL 2005 database. I am trying to query the data from two fields that contain sequence numbers. The fields are PalletRef3 and PalletRef4 which are text fields. For one particular customer these two fields will have numeric start and end sequence numbers - I want to be able to search on them from my Web page. I've used cast to convert the text to numbers and the View seems to work fine, but as soon as I try and search from within my web app, I get an error about not being able to convert a text value to numeric. Customers other than the POL03 account will have text type info in these fields, but the POL03 will always be numeric.

The SebCageCards view I have below works fine from a list all point of view, but as soon as I try and filter on it, the view seems to check ALL the data in the database and falls over when it hits other customers. Is there a way to make the view work only with the POL03 data?

this view is SebStockList

SELECT     TOP (100) PERCENT Stock.StockCode, MAX(Stock.StockDesc) AS StockDesc, COUNT(Pallets.OriginalPID) AS PID, SUM(StockList.QtyD) AS Qty,  MIN(Pallets.OtherDate) AS OtherDate, MAX(Pallets.Status) AS PalletRef, Pallets.Status, InSource.Code, Pallets.WarehouseNo, Pallets.PalletId, Pallets.StockListId, StockList.QtyB, StockList.QtyC, StockList.RatioB, StockList.RatioC, StockList.QtyD, StockList.Quantity, dbo.Stores.StoreName, Pallets.Col, Pallets.Row, dbo.Aisles.AisleName, Pallets.PalletRef1, Pallets.PalletRef2, Pallets.PalletRef3, Pallets.PalletRef4, CAST(dbo.Stores.StoreName AS varchar(1)) + CAST(dbo.Aisles.AisleName AS varchar(2)) + CAST(Pallets.Col AS varchar(2)) + CAST(Pallets.Row AS varchar(1)) AS Location, Stock.SourceId, Stock.StockId, Stock.ItemDescription1, Stock.ItemDescription2, Pallets.MrId, Pallets.MrIdOut, Stock.CountryOrigin, Pallets.CurrentStatus
FROM         dbo.Stock AS Stock INNER JOIN
                      dbo.Companies AS InSource ON Stock.SourceId = InSource.CompanyId INNER JOIN
                      dbo.Companies AS InOwner ON Stock.OwnerId = InOwner.CompanyId INNER JOIN
                      dbo.StockList AS StockList ON Stock.StockId = StockList.StockId INNER JOIN
                      dbo.Pallets AS Pallets ON StockList.StockListId = Pallets.StockListId INNER JOIN
                      dbo.Aisles ON Pallets.AisleId = dbo.Aisles.AisleId INNER JOIN
                      dbo.Stores ON dbo.Aisles.StoreId = dbo.Stores.StoreId
WHERE     (Pallets.MrIdOut = 0)
GROUP BY Stock.StockCode, Pallets.Status, InSource.Code, Pallets.WarehouseNo, Pallets.PalletId, Pallets.StockListId, StockList.QtyB, StockList.QtyC, StockList.RatioB, StockList.RatioC, StockList.QtyD, StockList.Quantity, dbo.Stores.StoreName, Pallets.Col, Pallets.Row, dbo.Aisles.AisleName, Pallets.PalletRef1, Pallets.PalletRef2, Pallets.PalletRef3, Pallets.PalletRef4, Stock.SourceId, Stock.StockId, Stock.ItemDescription1, Stock.ItemDescription2, Pallets.MrId, Pallets.MrIdOut, Stock.CountryOrigin, Pallets.CurrentStatus
HAVING      (Pallets.CurrentStatus = 0)
ORDER BY Stock.StockCode



This view is SebCageCards
SELECT     StockCode, StockDesc, PID, Qty, OtherDate, PalletRef, Status, Code, WarehouseNo, PalletId, StockListId, QtyB, QtyC, RatioB, RatioC, QtyD, Quantity,  StoreName, Col, Row, AisleName, PalletRef1, PalletRef2, PalletRef3, PalletRef4, Location, SourceId, StockId, ItemDescription1, ItemDescription2, MrId, MrIdOut, CountryOrigin, CurrentStatus, CAST(PalletRef3 AS INT) AS StartSeq, CAST(PalletRef4 AS INT) AS EndSeq
FROM         dbo.SebStockList
WHERE     (Code = 'POL03') AND (PalletRef3 <> '')

Answer : SQL View problems with Cast and display on a Web page

You can get away with 1 server then. Your dedicated SQL server *might* be a candidate, but OCS 2007 R2 is 64-bit only, and I see that your SQL server is running 2003 (no mention of architecture) so that may not be an option.

If you don't mind forcing home users to connect via VPN before firing up communicator then you can get by without an edge server as well. However an edge server does make things easier so if you can swing it, I'd still recommend it.

Random Solutions  
 
programming4us programming4us