tonyvee1973
IS-IT--Management
Hi All
I have a n error message when running the script below, it states "Msg 102, Level 15, State 1, Line 27 Incorrect syntax near ','."
Can anyone point me in the right direction please as this is my first time grouping?
Many thanks
SELECT dbo.SL_ACCOUNTS.CUCODE, dbo.SL_ACCOUNTS.CUCODE AS HeadOfficeAccount, dbo.SL_ACCOUNTS.CUNAME, dbo.ps_addresses.AddressLine1,
dbo.ps_addresses.AddressLine2, dbo.ps_addresses.AddressLine3, dbo.ps_addresses.AddressLine4, dbo.ps_addresses.AddressLine5,
dbo.SL_ACCOUNTS.CUPHONE, dbo.SL_ACCOUNTS.CUFAX, dbo.SL_ACCOUNTS.CU_TOT_DISC, dbo.SL_ACCOUNTS.CU_SETT_DISC_1,
dbo.SL_ACCOUNTS.CU_CREDIT_LIMIT, '' AS DaysForNextVisit, '' AS CompanyRegNumber, '' AS BankName, '' AS BankAddress1, '' AS BankAddress2,
'' AS BankTown, '' AS BankCounty, '' AS BankPostCode, '' AS BankTelephone, '' AS BankAccount, '' AS BankSortCode, '' AS ProprietorsName,
'' AS ProprietorsAddress1, '' AS ProprietorsAddress2, '' AS ProprietorsTown, '' AS ProprietorsCounty, '' AS ProprietorsPostCode,
'' AS ProprietorsTelephone, dbo.SL_ACCOUNTS.CUCONTACT, REPLACE(REPLACE(dbo.SL_ACCOUNTS.CU_ON_STOP, '0', 'N'), '1', 'Y') AS CU_ON_STOP,
dbo.SL_ACCOUNTS.CU_PRICE_KEY AS PricelistNumber, dbo.SL_ACCOUNTS.CUUSER1, dbo.SL_ACCOUNTS.CUTURNOVERPTD,
dbo.SL_ACCOUNTS.CUTURNOVERYTD, '' AS LastYearSales, dbo.SL_ACCOUNTS.CUBALANCE, '' AS Notes1, '' AS Notes2,
dbo.SL_ACCOUNTS.CUCURRENCYCODE, '' AS Tax, '' AS ConfirmOrders, '' AS GenericCode3, '' AS GenericCode4, REPLACE(CONVERT(varchar(255),
dbo.SL_ACCOUNTS.CU_NOTES), CHAR(13), ' ') AS Freetype1, '' AS Freetype2, dbo.SL_ACCOUNTS.CU_EMAIL,
dbo.SL_ACCOUNTS.CUUSER2 AS PriceCode, '' AS DiscountCode, dbo.SL_ACCOUNTS.CUAGED_1 AS CurrentMonthBalance,
dbo.SL_ACCOUNTS.CUAGED_2 AS [Month+1], dbo.SL_ACCOUNTS.CUAGED_3 AS [Month+2], dbo.SL_ACCOUNTS.CUAGED_4 AS [Month+3],
dbo.SL_ACCOUNTS.CU_DATE_INV, '' AS AmountLastInvoice, dbo.SL_ACCOUNTS.CU_DATE_PAY, '' AS AmountLastPayment, '' AS MinOrderValue,
dbo.SL_ACCOUNTS2.CU_FLAG1 AS PORefRequired, '' AS NoteDateRequired, '' AS PostOrderDiscount, 'N' AS UsrBreakDisc, '' AS JournalGroupCode,
'' AS TaxRegion, '' AS DefaultLocationCode, '' AS DefaultGeneric18, '' AS DefaultGeneric19, '' AS DefaultGeneric20, '' AS DefaultGeneric21,
'' AS DefaultGeneric22, '' AS DefaultGeneric23, dbo.SL_ACCOUNTS2.CU_USRFLAG2
FROM dbo.SL_ACCOUNTS INNER JOIN
dbo.ps_addresses ON dbo.SL_ACCOUNTS.CUCODE = dbo.ps_addresses.AccountNumber INNER JOIN
dbo.SL_ACCOUNTS2 ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_ACCOUNTS2.CUCODE2 INNER JOIN
dbRD_HEADER ON dbo.SL_ACCOUNTS.CUCODE = dbRD_HEADER.OH_ACCOUNT
GROUP BY dbo.SL_ACCOUNTS.CUCODE, dbo.SL_ACCOUNTS.CUCODE, dbo.SL_ACCOUNTS.CUNAME, dbo.ps_addresses.AddressLine1, dbo.ps_addresses.AddressLine2, dbo.ps_addresses.AddressLine3,
dbo.ps_addresses.AddressLine4, dbo.ps_addresses.AddressLine5, dbo.SL_ACCOUNTS.CUPHONE, dbo.SL_ACCOUNTS.CUFAX, dbo.SL_ACCOUNTS.CU_TOT_DISC, dbo.SL_ACCOUNTS.CU_SETT_DISC_1,
dbo.SL_ACCOUNTS.CU_CREDIT_LIMIT, dbo.SL_ACCOUNTS.CUCONTACT, dbo.SL_ACCOUNTS.CU_ON_STOP, dbo.SL_ACCOUNTS.CU_PRICE_KEY, dbo.SL_ACCOUNTS.CUUSER1,
dbo.SL_ACCOUNTS.CUTURNOVERPTD, dbo.SL_ACCOUNTS.CUTURNOVERYTD, dbo.SL_ACCOUNTS.CUBALANCE, dbo.SL_ACCOUNTS.CUCURRENCYCODE, REPLACE(CONVERT(varchar(255), dbo.SL_ACCOUNTS.CU_NOTES,
dbo.SL_ACCOUNTS.CU_EMAIL, dbo.SL_ACCOUNTS.CUUSER2, dbo.SL_ACCOUNTS.CUAGED_1, dbo.SL_ACCOUNTS.CUAGED_2, dbo.SL_ACCOUNTS.CUAGED_3, dbo.SL_ACCOUNTS.CUAGED_4,
dbo.SL_ACCOUNTS.CU_DATE_INV, dbo.SL_ACCOUNTS.CU_DATE_PAY, dbo.SL_ACCOUNTS2.CU_FLAG1, dbo.SL_ACCOUNTS2.CU_USRFLAG2
I have a n error message when running the script below, it states "Msg 102, Level 15, State 1, Line 27 Incorrect syntax near ','."
Can anyone point me in the right direction please as this is my first time grouping?
Many thanks
SELECT dbo.SL_ACCOUNTS.CUCODE, dbo.SL_ACCOUNTS.CUCODE AS HeadOfficeAccount, dbo.SL_ACCOUNTS.CUNAME, dbo.ps_addresses.AddressLine1,
dbo.ps_addresses.AddressLine2, dbo.ps_addresses.AddressLine3, dbo.ps_addresses.AddressLine4, dbo.ps_addresses.AddressLine5,
dbo.SL_ACCOUNTS.CUPHONE, dbo.SL_ACCOUNTS.CUFAX, dbo.SL_ACCOUNTS.CU_TOT_DISC, dbo.SL_ACCOUNTS.CU_SETT_DISC_1,
dbo.SL_ACCOUNTS.CU_CREDIT_LIMIT, '' AS DaysForNextVisit, '' AS CompanyRegNumber, '' AS BankName, '' AS BankAddress1, '' AS BankAddress2,
'' AS BankTown, '' AS BankCounty, '' AS BankPostCode, '' AS BankTelephone, '' AS BankAccount, '' AS BankSortCode, '' AS ProprietorsName,
'' AS ProprietorsAddress1, '' AS ProprietorsAddress2, '' AS ProprietorsTown, '' AS ProprietorsCounty, '' AS ProprietorsPostCode,
'' AS ProprietorsTelephone, dbo.SL_ACCOUNTS.CUCONTACT, REPLACE(REPLACE(dbo.SL_ACCOUNTS.CU_ON_STOP, '0', 'N'), '1', 'Y') AS CU_ON_STOP,
dbo.SL_ACCOUNTS.CU_PRICE_KEY AS PricelistNumber, dbo.SL_ACCOUNTS.CUUSER1, dbo.SL_ACCOUNTS.CUTURNOVERPTD,
dbo.SL_ACCOUNTS.CUTURNOVERYTD, '' AS LastYearSales, dbo.SL_ACCOUNTS.CUBALANCE, '' AS Notes1, '' AS Notes2,
dbo.SL_ACCOUNTS.CUCURRENCYCODE, '' AS Tax, '' AS ConfirmOrders, '' AS GenericCode3, '' AS GenericCode4, REPLACE(CONVERT(varchar(255),
dbo.SL_ACCOUNTS.CU_NOTES), CHAR(13), ' ') AS Freetype1, '' AS Freetype2, dbo.SL_ACCOUNTS.CU_EMAIL,
dbo.SL_ACCOUNTS.CUUSER2 AS PriceCode, '' AS DiscountCode, dbo.SL_ACCOUNTS.CUAGED_1 AS CurrentMonthBalance,
dbo.SL_ACCOUNTS.CUAGED_2 AS [Month+1], dbo.SL_ACCOUNTS.CUAGED_3 AS [Month+2], dbo.SL_ACCOUNTS.CUAGED_4 AS [Month+3],
dbo.SL_ACCOUNTS.CU_DATE_INV, '' AS AmountLastInvoice, dbo.SL_ACCOUNTS.CU_DATE_PAY, '' AS AmountLastPayment, '' AS MinOrderValue,
dbo.SL_ACCOUNTS2.CU_FLAG1 AS PORefRequired, '' AS NoteDateRequired, '' AS PostOrderDiscount, 'N' AS UsrBreakDisc, '' AS JournalGroupCode,
'' AS TaxRegion, '' AS DefaultLocationCode, '' AS DefaultGeneric18, '' AS DefaultGeneric19, '' AS DefaultGeneric20, '' AS DefaultGeneric21,
'' AS DefaultGeneric22, '' AS DefaultGeneric23, dbo.SL_ACCOUNTS2.CU_USRFLAG2
FROM dbo.SL_ACCOUNTS INNER JOIN
dbo.ps_addresses ON dbo.SL_ACCOUNTS.CUCODE = dbo.ps_addresses.AccountNumber INNER JOIN
dbo.SL_ACCOUNTS2 ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_ACCOUNTS2.CUCODE2 INNER JOIN
dbRD_HEADER ON dbo.SL_ACCOUNTS.CUCODE = dbRD_HEADER.OH_ACCOUNT
GROUP BY dbo.SL_ACCOUNTS.CUCODE, dbo.SL_ACCOUNTS.CUCODE, dbo.SL_ACCOUNTS.CUNAME, dbo.ps_addresses.AddressLine1, dbo.ps_addresses.AddressLine2, dbo.ps_addresses.AddressLine3,
dbo.ps_addresses.AddressLine4, dbo.ps_addresses.AddressLine5, dbo.SL_ACCOUNTS.CUPHONE, dbo.SL_ACCOUNTS.CUFAX, dbo.SL_ACCOUNTS.CU_TOT_DISC, dbo.SL_ACCOUNTS.CU_SETT_DISC_1,
dbo.SL_ACCOUNTS.CU_CREDIT_LIMIT, dbo.SL_ACCOUNTS.CUCONTACT, dbo.SL_ACCOUNTS.CU_ON_STOP, dbo.SL_ACCOUNTS.CU_PRICE_KEY, dbo.SL_ACCOUNTS.CUUSER1,
dbo.SL_ACCOUNTS.CUTURNOVERPTD, dbo.SL_ACCOUNTS.CUTURNOVERYTD, dbo.SL_ACCOUNTS.CUBALANCE, dbo.SL_ACCOUNTS.CUCURRENCYCODE, REPLACE(CONVERT(varchar(255), dbo.SL_ACCOUNTS.CU_NOTES,
dbo.SL_ACCOUNTS.CU_EMAIL, dbo.SL_ACCOUNTS.CUUSER2, dbo.SL_ACCOUNTS.CUAGED_1, dbo.SL_ACCOUNTS.CUAGED_2, dbo.SL_ACCOUNTS.CUAGED_3, dbo.SL_ACCOUNTS.CUAGED_4,
dbo.SL_ACCOUNTS.CU_DATE_INV, dbo.SL_ACCOUNTS.CU_DATE_PAY, dbo.SL_ACCOUNTS2.CU_FLAG1, dbo.SL_ACCOUNTS2.CU_USRFLAG2