Adding "not in" statement to my SQL command makes the whole thing extremely slow. Any suggestion on how to get around this would be greatly appreciated!
select distinct
d.fiscal_year,d.calendar_year,d.month_num
from vw_ePCR_eMeds_tickets v
inner join incident_date_dim d on v.ticketdos=d.inci_date
left join vw_all_incidents i on i.CADIncidentNumber=v.incident_num
where TicketDOS between '12/01/2017' and '05/31/2018'
and [transportedstatus] = 'transported'
and i.call_type_id not in (
select call_type_id
from DW_EMS_Elite.dbo.MCFRS_EMS_BillingExclude
)
Just give it a try
with cte as (
select call_type_id from DW_EMS_Elite.dbo.MCFRS_EMS_BillingExclude
)
select distinct
d.fiscal_year,
d.calendar_year,
d.month_num
from
vw_ePCR_eMeds_tickets as v
join incident_date_dim as d on ( v.ticketdos=d.inci_date )
left join vw_all_incidents as i on ( i.CADIncidentNumber=v.incident_num )
left join cte as c on ( c.call_type_id = i.call_type_id )
where
( ( '20171201'<= TicketDOS ) and ( TicketDOS < '20180601' ) )
and ( [transportedstatus] = 'transported' )
and ( c.call_type_id is null )
Related
I am new in MySQL I have a db2 select and a would like to do this in MSsql and with WITH clause
db2
1 SQL.
SELECT
SQLUSER.TT_VALUTRAZ.SIFRA3,
SQLUSER.TT_VALUTRAZ.SIFVAL32,
SQLUSER.TT_VALUTRAZ.DATUM,
SQLUSER.TT_VALUTRAZ.RAZMERJE
FROM
SQLUSER.TT_VALUTRAZ
WHERE
(
(SQLUSER.TT_VALUTRAZ.DATUM >= '1.5.2007')
) ---> this go to DW.TEMP_PFPC_TT_VALUTRAZ
2 sql.
SELECT
'705' AS SIFRA3,
'891' AS SIFVAL32,
A.DATUM,
A.RAZMERJE AS RAZMERJE
FROM
DW.TEMP_PFPC_TT_VALUTRAZ A
WHERE
A.DATUM >= '1.5.2007' AND
A.SIFRA3 = '891' AND
A.SIFVAL32 = '978' AND
('705', '891', A.DATUM) NOT IN
(
SELECT
SIFRA3,
SIFVAL32,
DATUM
FROM
DW.TEMP_PFPC_TT_VALUTRAZ
WHERE
SIFRA3 = '705' AND
SIFVAL32 = '891'
)
now I like to join this two SQL statement and would like to use ons with clause and MSsql syntax
There are many ways of doing this. I only posted one way. There are some places that have been changed due to syntax issues. Let me know this answer if this answer is useful.
; WITH CTE_1 AS ( SELECT
SQLUSER.TT_VALUTRAZ.SIFRA3,
SQLUSER.TT_VALUTRAZ.SIFVAL32,
SQLUSER.TT_VALUTRAZ.DATUM,
SQLUSER.TT_VALUTRAZ.RAZMERJE
FROM
SQLUSER.TT_VALUTRAZ
WHERE
(
(SQLUSER.TT_VALUTRAZ.DATUM >= '1.5.2007')
) ---> this go to DW.TEMP_PFPC_TT_VALUTRAZ
)
, CTE_2 AS (
SELECT * FROM
(
SELECT
'705' AS SIFRA3,
'891' AS SIFVAL32,
A.DATUM,
A.RAZMERJE AS RAZMERJE
FROM
DW.TEMP_PFPC_TT_VALUTRAZ A
) AS B
WHERE
B.DATUM >= '1.5.2007' AND
B.SIFRA3 = 891 AND
B.SIFVAL32 = 978 AND
B.SIFRA3 NOT IN (705) --use of sub queries in where clause has been fixed.
AND B.SIFVAL32 NOT IN (891) --use of sub queries in where clause has been fixed.
AND B.DATUM NOT IN
(
SELECT
DATUM
FROM
DW.TEMP_PFPC_TT_VALUTRAZ
)
)
SELECT * FROM
CTE_1 AS [C]
INNER JOIN CTE_2 AS [CT]
ON [CTE_1]. [SIFRA3] = [CT].[SIFRA3]
AND [C]. [SIFVAL32] = [CT].[SIFVAL32]
AND [C].[DATUM] = [CT].[DATUM]
AND [C].[RAZMERJE] = [CT].[RAZMERJE]
Hi this code runs perfectly as a query but when i try to parse it as a view i have the error on the title of this post. "Each Group by expression must contain at least one column that is not an outer reference". I need a second pair of eyes to help me work around this problem.
Thank you!
SELECT Codigo, Nome, DataNascimento, IDADE, DataAdmissao, FUNCAO, CodEstabelecimento, Vencimento
, 'GRATIFICACOES' AS Expr1, 'SUB.TURNO' AS Expr2, OUTROS, DataUltProcessamento, 'DESCONTO MULTAS' AS Expr3
, AntiguidadeMeses, 'FALTAS' AS Expr4, Ano
FROM (
SELECT F.Codigo, F.Nome, F.DataNascimento, (
SELECT FLOOR((CAST(GETDATE() AS INTEGER) - CAST(F.DataNascimento AS INTEGER)) / 365.25) AS Expr1
) AS IDADE, F.DataAdmissao, (
SELECT Descricao
FROM dbo.Categorias
WHERE (Categoria = F.Categoria)
) AS FUNCAO, F.Categoria, F.CodEstabelecimento, F.Vencimento, (
SELECT SUM(Valor) AS G
FROM dbo.FuncRem
WHERE (
Remuneracao IN (
'R21'
,'R23'
,'R24'
,'R25'
,'R94'
,'R96'
)
)
AND (Funcionario = F.Codigo)
) AS 'GRATIFICACOES', (
SELECT SUM(Valor) AS ST
FROM dbo.FuncRem AS FuncRem_2
WHERE (
Remuneracao IN (
'R05'
,'R22'
,'R43'
,'R50'
)
)
AND (Funcionario = F.Codigo)
) AS 'SUB.TURNO', (
SELECT SUM(Valor) AS O
FROM dbo.FuncRem AS FuncRem_1
WHERE (
Remuneracao NOT IN (
'R21'
,'R23'
,'R24'
,'R25'
,'R94'
,'R96'
,'R05'
,'R22'
,'R43'
,'R50'
)
)
AND (Funcionario = F.Codigo)
) AS OUTROS, (
SELECT SUM(Valor) AS A
FROM dbo.MovimentosFuncionarios
WHERE (CodMov = 'D15')
AND (Funcionario = F.Codigo)
) AS 'DESCONTO MULTAS', F.DataUltProcessamento, DATEDIFF(m, F.DataAdmissao, GETDATE())
AS AntiguidadeMeses, (
SELECT SUM(Tempo) AS F
FROM dbo.CadastroFaltas
WHERE (
Falta IN (
'F12'
,'F10'
)
)
AND (Funcionario = F.Codigo)
AND (YEAR(Data) = M.Ano)
) AS 'FALTAS', M.Ano
FROM dbo.Funcionarios AS F
INNER JOIN dbo.Situacoes AS S ON F.Situacao = S.Situacao
LEFT OUTER JOIN dbo.FuncRem AS FR ON FR.Funcionario = F.Codigo
LEFT OUTER JOIN dbo.MovimentosFuncionarios AS M ON F.Codigo = M.Funcionario
LEFT OUTER JOIN dbo.CadastroFaltas AS CF ON CF.Funcionario = F.Codigo
WHERE (S.Tipo = 0)
AND (
F.CodDepartamento IN (
912
,914
,916
,921
,922
,924
,931
,934
,937
)
)
AND (M.Ano = 2016)
GROUP BY F.Codigo, F.Nome, F.DataNascimento, F.DataAdmissao, F.Categoria, F.CodEstabelecimento
, F.Vencimento, F.DataUltProcessamento, F.Situacao, CF.Falta, M.Ano, CF.Tempo, FR.Remuneracao
, FR.Valor, M.CodMov, M.Valor
) AS R
GROUP BY Codigo, Nome, DataNascimento, IDADE, DataAdmissao, FUNCAO, CodEstabelecimento, Vencimento
, AntiguidadeMeses, DataUltProcessamento, 'GRATIFICACOES', 'FALTAS', 'SUB.TURNO', OUTROS, 'DESCONTO MULTAS', Ano
I am trying to link two servers (the host is SQL Server 2008 and the destination is ORACLE) so that a table on the oracle server is populated by data held in multiple tables on the SQL server.
I have set up an INSERT OPENQUERY, which works perfectly fine. I also want to setup another query to update those records.
So, my insert query, selects records created in the last 24 hours, and inserts them, no problem. But I am struggling to create an UPDATE OPENQUERY script, that will run every 24 hours to make the relevant changes.
Here is my INSERT
INSERT OPENQUERY(ukdev662, 'SELECT DOCKET_NUMBER,
APP_NUMBER,
ATT,
LIT_H,
REVIEW,
COUNTRY,
NOTICE,
COUNTRY_CODE,
FORMALITY_NAME
FROM GWDMDV29.LOOKUPS__IPMANAGER')
SELECT PMasters.DocketNumber + ISNULL(Codes_RelationType.Code, '') + ISNULL(PMasters.FilingNumber, '') + 'PTE'
,ISNULL(PMasters.AppNumber, '[null]')
,ISNULL(PartyDetails_Att.Party, 'Att not assigned')
,0
,CONVERT(DATETIME, '20130128')
,uktst1633.dbo.Countries.Description
,'Preserve'
,uktst1633.dbo.Countries.WIPO
,ISNULL(PartyDetails_Associate.Party, '[null]')
FROM uktst1633.dbo.Countries
RIGHT OUTER JOIN uktst1633.dbo.PatentMasters PMasters
ON ( PMasters.Country = uktst1633.dbo.Countries.CountryID )
INNER JOIN uktst1633.dbo.Codes Codes_CType
ON ( PMasters.CType = Codes_CType.CodeID
AND Codes_CType.CodeTypeID = 'CSP'
)
INNER JOIN uktst1633.dbo.Codes Codes_RelationType
ON ( Codes_RelationType.CodeID = PMasters.RelationType
AND Codes_RelationType.CodeTypeID = 'RLP'
)
LEFT OUTER JOIN uktst1633.dbo.Parties Parties_Att
ON ( Parties_Att.PartyID = PMasters.Att
AND ( Parties_Att.PartyTypeID = 'ATP'
OR Parties_Att.PartyTypeID IS NULL
)
)
LEFT OUTER JOIN uktst1633.dbo.PartyDetails PartyDetails_Att
ON ( PartyDetails_Att.PartyDetailID = Parties_Att.PartyDetailID )
LEFT OUTER JOIN uktst1633.dbo.Parties Parties_Associate
ON ( Parties_Associate.PartyID = PMasters.Associate
AND ( Parties_Associate.PartyTypeID = 'AGP'
OR Parties_Associate.PartyTypeID IS NULL
)
)
LEFT OUTER JOIN uktst1633.dbo.PartyDetails PartyDetails_Associate
ON ( PartyDetails_Associate.PartyDetailID = Parties_Associate.PartyDetailID )
WHERE ( ( Codes_RelationType.Description = 'CONTINUATION'
OR Codes_RelationType.Description = 'DIVISION'
)
AND Codes_CType.Description = 'Regular'
AND PMasters.CreateDate >= DATEADD(day, -1, GETDATE())
)
Thanks for any help . I have searched around and cannot find much on OPENQUERY, it all seems to be pretty basic stuff. I tried following this syntax's examples but it got me nowhere...
UPDATE
Table
SET
Table.col1 = other_table.col1,
Table.col2 = other_table.col2
FROM
Table
INNER JOIN
other_table
ON
Table.id = other_table.id
I'm trying to convert a report query from Access to SQL SERVER 2008. Using the same database but i can't get the same results. not even close. The Access query is like this:
SELECT Sum(INPUT_ItemSaleLines.TaxExclusiveTotal) AS TotalexTax,([TotalexTax])- Sum( Nz([SumOfTaxExclusiveAmount])+ Nz([CostOfGoodsSoldAmount])+ Nz
(
Nz
( IIf
( Left([Input_Items.ItemNumber],5)='31-63',136*[Quantity]/1000,
IIf(Left([Input_Items.ItemNumber],6)='34S-63',200*[Quantity]/1000)
)
)+ Nz
( IIf
( Left([Input_Items.ItemNumber],5)='34-63',250*[Quantity]/1000,
IIf(Left([Input_Items.ItemNumber],6)='26-63',250*[Quantity]/1000)
)
)
)
) AS Margin,
INPUT_Cards_1.Name AS SalesPerson, INPUT_Sales.SalesPersonID,
INPUT_Sales.InvoiceStatusID, INPUT_Cards.Name, INPUT_Items.ItemName,
Sum(INPUT_ItemSaleLines.Quantity) AS TotalQty,
Sum(INPUT_ItemSaleLines.CostOfGoodsSoldAmount) AS TotalCOGS,
Count(INPUT_Sales.SaleID) AS [Number of Sales],
Sum(qryShippingTotalexGST.SumOfTaxExclusiveAmount) AS ShippingTotal
FROM
( qryShippingTotalexGST RIGHT JOIN
(
(
(
INPUT_Items INNER JOIN INPUT_ItemSaleLines
ON INPUT_Items.ItemID = INPUT_ItemSaleLines.ItemID
) INNER JOIN INPUT_Sales ON INPUT_ItemSaleLines.SaleID = INPUT_Sales.SaleID
) INNER JOIN INPUT_Cards ON INPUT_Sales.CardRecordID = INPUT_Cards.CardRecordID
) ON qryShippingTotalexGST.JobID = INPUT_ItemSaleLines.JobID
) LEFT JOIN INPUT_Cards AS INPUT_Cards_1 ON INPUT_Sales.SalesPersonID = INPUT_Cards_1.CardRecordID
WHERE
(((INPUT_Sales.Date) Between [Forms]![MenuReports]![StartDate] And [Forms]![MenuReports]![EndDate]))
GROUP BY INPUT_Items.ItemNumber,
INPUT_Cards_1.Name, INPUT_Sales.SalesPersonID, INPUT_Sales.InvoiceStatusID,
INPUT_Cards.Name, INPUT_Items.ItemName
HAVING
(((INPUT_Sales.InvoiceStatusID)<>"OR"));
Then the SQL Server script that i write like this:
SELECT MYOBItems.ItemName, MYOBCards.Name AS SalesPerson, MYOBCards1.Name,
SUM(MYOBsalesLines.Qty) AS TotalQty,
SUM(MYOBsalesLines.CostOfGoodsSoldAmount) AS TotalCOGS,
COUNT(MYOBSales.SaleID) AS NumberOfSales,
SUM(MYOBsalesLines.TaxExclusiveAmount) AS TotalexTax,
SUM(cast(MYOBJobsShippingTotals.TaxExclusiveAmount AS Decimal(18,2))) AS ShippingTotal,
(SUM(MYOBsalesLines.TaxExclusiveAmount)) - SUM
(
COALESCE(cast(MYOBJobsShippingTotals.TaxExclusiveAmount AS Decimal(18,2)),0)+ COALESCE(MYOBsalesLines.CostOfGoodsSoldAmount,0)+ COALESCE
(
COALESCE
(
CASE
WHEN LEFT(MYOBItems.ItemNumber,5) = '31-63' THEN (136*MYOBsalesLines.Qty/1000)
WHEN LEFT(MYOBItems.ItemNumber,6) = '34S-63' THEN (200*MYOBsalesLines.Qty/1000)
ELSE 0
END, 0
)+ COALESCE
(
CASE
WHEN LEFT(MYOBItems.ItemNumber,5) = '34-63' THEN (250*MYOBsalesLines.Qty/1000)
WHEN LEFT(MYOBItems.ItemNumber,6) = '26-63' THEN (250*MYOBsalesLines.Qty/1000)
ELSE 0
END , 0
), 0
)
)AS Margin
, MYOBSales.InvoiceStatusID FROM
( MYOBJobsShippingTotals RIGHT JOIN
(
(
(
MYOBItems INNER JOIN MYOBsalesLines
ON MYOBItems.ItemID = MYOBsalesLines.ItemID
) INNER JOIN MYOBSales ON MYOBsalesLines.SaleID = MYOBSales.SaleID
AND MYOBSales.ElevateCompanyID = MYOBsalesLines.ElevateCompanyID
) INNER JOIN MYOBCards AS MYOBCards1 ON MYOBSales.CardRecordID = MYOBCards1.CardRecordID
AND MYOBsalesLines.ElevateCompanyID = MYOBCards1.ElevateCompanyID
AND MYOBSales.ElevateCompanyID = MYOBCards1.ElevateCompanyID
) ON MYOBJobsShippingTotals.JobID = MYOBsalesLines.JobID
) LEFT JOIN MYOBCards ON MYOBSales.SalesPersonID = MYOBCards.CardRecordID
GROUP BY MYOBItems.ItemName, MYOBCards.Name,
MYOBCards1.Name, MYOBSales.InvoiceStatusID
I suspect there was something wrong with the joined tables but not sure how to fix it.
Is there any mistake in my SQL Server script that is not relevant with the Access syntax?
Thank for the help in advance. and sorry for my long scripts.
Your SQL server query is missing the WHERE and HAVING clauses of the MS Access query, it's GROUP BY clause doesn't have the same number or order of columns as the MS Access query, and has additional JOIN criteria that wasn't in the MS Access query.
A more faithful conversion would look like this:
SELECT SUM(MYOBsalesLines.TaxExclusiveAmount) AS TotalexTax
, SUM(MYOBsalesLines.TaxExclusiveAmount)
- SUM
(
COALESCE(cast(MYOBJobsShippingTotals.TaxExclusiveAmount AS Decimal(18,2)), 0)
+ COALESCE(MYOBsalesLines.CostOfGoodsSoldAmount,0)
+ COALESCE
(
COALESCE
(
CASE
WHEN LEFT(MYOBItems.ItemNumber,5) = '31-63' THEN (136*MYOBsalesLines.Qty/1000)
WHEN LEFT(MYOBItems.ItemNumber,6) = '34S-63' THEN (200*MYOBsalesLines.Qty/1000)
ELSE 0
END
, 0
)
+ COALESCE
(
CASE
WHEN LEFT(MYOBItems.ItemNumber,5) = '34-63' THEN (250*MYOBsalesLines.Qty/1000)
WHEN LEFT(MYOBItems.ItemNumber,6) = '26-63' THEN (250*MYOBsalesLines.Qty/1000)
ELSE 0
END
, 0
)
, 0
)
)
AS Margin
, MYOBCards1.Name AS SalesPerson
, MYOBSales.SalesPersonID
, MYOBSales.InvoiceStatusID
, MYOBCards.Name
, MYOBItems.ItemName
, SUM(MYOBsalesLines.Qty) AS TotalQty
, SUM(MYOBsalesLines.CostOfGoodsSoldAmount) AS TotalCOGS
, COUNT(MYOBSales.SaleID) AS NumberOfSales
, SUM(cast(MYOBJobsShippingTotals.TaxExclusiveAmount AS Decimal(18,2))) AS ShippingTotal
FROM
(
MYOBJobsShippingTotals RIGHT JOIN
(
(
(
MYOBItems INNER JOIN MYOBsalesLines
ON MYOBItems.ItemID = MYOBsalesLines.ItemID
) INNER JOIN MYOBSales ON MYOBsalesLines.SaleID = MYOBSales.SaleID
) INNER JOIN MYOBCards ON MYOBSales.CardRecordID = MYOBCards.CardRecordID
) ON MYOBJobsShippingTotals.JobID = MYOBsalesLines.JobID
) LEFT JOIN MYOBCards AS MYOBCards1 ON MYOBSales.SalesPersonID = MYOBCards1.CardRecordID
WHERE MYOBSales.Date BETWEEN ? AND ?
GROUP BY MYOBItems.ItemNumber
, MYOBCards1.Name
, MYOBSales.SalesPersonID
, MYOBSales.InvoiceStatusID
, MYOBCards.Name
, MYOBItems.ItemName
HAVING MYOBSales.InvoiceStatusID <> 'OR'
Where the two question marks are your [Forms]![MenuReports]![StartDate] and [Forms]![MenuReports]![EndDate] values.
I had a view that worked, I edited it in SQL Server Mgmt Studio, it didn't work, I took out the changes and saved it down, it still doesn't work despite reverting it back to its original state.
I'm getting the error
Joined tables cannot be specified in a query containing outer join
operators. View or function 'adept_invoiced' contains joined tables.
I've googled around and come up with a possible join syntax problem due to the view being written in 2001 and me trying to edit it (for the first time) in Management Studio.
The view ran perfectly for years until I edited it this morning.
This is the From/Where section....
FROM dbo.SYS_COMP_ADDRESS
CROSS JOIN dbo.SL_ACCOUNTS
INNER JOIN dbo.SL_TRANSACTIONS
INNER JOIN dbo.ORD_HEADER
ON dbo.SL_TRANSACTIONS.ST_ORDER_NUMBER =
dbo.ORD_HEADER.OH_ORDER_NUMBER
INNER JOIN dbo.SL_PL_NL_DETAIL
LEFT OUTER JOIN dbo.STK_STOCK
ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
dbo.STK_STOCK.STKCODE
INNER JOIN dbo.ORD_DETAIL
ON dbo.SL_PL_NL_DETAIL.DET_ORDER_LINK =
dbo.ORD_DETAIL.OD_PRIMARY
LEFT OUTER JOIN dbo.STK_STOCK3
ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
dbo.STK_STOCK3.STKCODE3
LEFT OUTER JOIN dbo.STK_STOCK_2
ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
dbo.STK_STOCK_2.STKCODE2
LEFT OUTER JOIN dbo.PRC_PRICE_RECS2
ON dbo.SL_PL_NL_DETAIL.DET_PRICE_CODE =
dbo.PRC_PRICE_RECS2.PRCODE2
ON dbo.SL_TRANSACTIONS.ST_HEADER_KEY =
dbo.SL_PL_NL_DETAIL.DET_HEADER_KEY
ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_TRANSACTIONS.ST_COPYCUST
INNER JOIN dbo.SL_ACCOUNTS2
ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_ACCOUNTS2.CUCODE2
WHERE ( dbo.SL_TRANSACTIONS.ST_TRANTYPE IN ( 'INV', 'CRN' ) )
AND ( dbo.SL_TRANSACTIONS.ST_BATCH_FLAG <> 1 )
AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023134' )
AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023265' )
AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%other income%' )
AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%supplier%' )
I'm not sure where it might be failing, or how to fix it!
Any help would be greatly appreciated.
Try this:
FROM dbo.SYS_COMP_ADDRESS
CROSS JOIN dbo.SL_ACCOUNTS
INNER JOIN dbo.SL_TRANSACTIONS
INNER JOIN dbo.ORD_HEADER
ON dbo.SL_TRANSACTIONS.ST_ORDER_NUMBER =
dbo.ORD_HEADER.OH_ORDER_NUMBER
INNER JOIN dbo.SL_PL_NL_DETAIL
ON dbo.SL_TRANSACTIONS.ST_HEADER_KEY =
dbo.SL_PL_NL_DETAIL.DET_HEADER_KEY
LEFT OUTER JOIN dbo.STK_STOCK
ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
dbo.STK_STOCK.STKCODE
INNER JOIN dbo.ORD_DETAIL
ON dbo.SL_PL_NL_DETAIL.DET_ORDER_LINK =
dbo.ORD_DETAIL.OD_PRIMARY
LEFT OUTER JOIN dbo.STK_STOCK3
ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
dbo.STK_STOCK3.STKCODE3
LEFT OUTER JOIN dbo.STK_STOCK_2
ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
dbo.STK_STOCK_2.STKCODE2
LEFT OUTER JOIN dbo.PRC_PRICE_RECS2
ON dbo.SL_PL_NL_DETAIL.DET_PRICE_CODE =
dbo.PRC_PRICE_RECS2.PRCODE2
ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_TRANSACTIONS.ST_COPYCUST
INNER JOIN dbo.SL_ACCOUNTS2
ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_ACCOUNTS2.CUCODE2
WHERE ( dbo.SL_TRANSACTIONS.ST_TRANTYPE IN ( 'INV', 'CRN' ) )
AND ( dbo.SL_TRANSACTIONS.ST_BATCH_FLAG <> 1 )
AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023134' )
AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023265' )
AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%other income%' )
AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%supplier%' )
Are you using the old style join syntax anywhere so search for *= and =* in your view definition