lhedgecoth
asked on
Convert Access query to SQL query
I copied the following query out of Access (I didn't write it) and I need to be able to run it in SQL, but I'm receiving error messages. Here is what I have so far:
SELECT DISTINCTROW dbo.Balances.CurrentBalanc e, dbo.Balances.Arrears1Balan ce,
dbo.Balances.Arrears2Balan ce, dbo.Balances.Arrears3Balan ce,
dbo.Balances.Arrears4PlusB alance, dbo.Customer.CustomerAcctN umber,
dbo.Customer.BillToName, dbo.Customer.BillToStreet1 , dbo.Customer.BillToStreet2 ,
dbo.Customer.BillToCity, dbo.Customer.BillToState, dbo.Customer.BillToZip,
dbo.Customer.CreditLimit, dbo.Customer.SocialSecurit yNumber, dbo.Customer.CustID,
dbo.Customer.BillingGroupI D, dbo.Customer.BillToCountry ,
IIf(Nz([CreditClass])=""," *",[Credit Class]) AS CrClass, dbo.SalesPersonnel.SalesGr oupID,
dbo.Customer.InvoiceRespon sible, dbo.BillingGroup.CompanyNa me
FROM ((Customer RIGHT JOIN dbo.Balances ON dbo.Customer.CustID = dbo.Balances.CustID)
LEFT JOIN dbo.BillingGroup ON dbo.Customer.BillingGroupI D = dbo.BillingGroup.BillingGr oupID)
LEFT JOIN dbo.SalesPersonnel ON dbo.Customer.SalesID = dbo.SalesPersonnel.SalesID
WHERE (((dbo.Customer.CustomerAc ctNumber)< >"") AND ((dbo.Customer.InvoiceResp onsible)=T rue));
These are the errors I'm receiving:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '.'.
Server: Msg 1038, Level 15, State 1, Line 8
Cannot use empty object or column names. Use a single space if necessary.
Server: Msg 170, Level 15, State 1, Line 13
Line 13: Incorrect syntax near 'dbo'.
Server: Msg 1038, Level 15, State 1, Line 13
Cannot use empty object or column names. Use a single space if necessary.
SELECT DISTINCTROW dbo.Balances.CurrentBalanc
dbo.Balances.Arrears2Balan
dbo.Balances.Arrears4PlusB
dbo.Customer.BillToName, dbo.Customer.BillToStreet1
dbo.Customer.BillToCity, dbo.Customer.BillToState, dbo.Customer.BillToZip,
dbo.Customer.CreditLimit, dbo.Customer.SocialSecurit
dbo.Customer.BillingGroupI
IIf(Nz([CreditClass])="","
dbo.Customer.InvoiceRespon
FROM ((Customer RIGHT JOIN dbo.Balances ON dbo.Customer.CustID = dbo.Balances.CustID)
LEFT JOIN dbo.BillingGroup ON dbo.Customer.BillingGroupI
LEFT JOIN dbo.SalesPersonnel ON dbo.Customer.SalesID = dbo.SalesPersonnel.SalesID
WHERE (((dbo.Customer.CustomerAc
These are the errors I'm receiving:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '.'.
Server: Msg 1038, Level 15, State 1, Line 8
Cannot use empty object or column names. Use a single space if necessary.
Server: Msg 170, Level 15, State 1, Line 13
Line 13: Incorrect syntax near 'dbo'.
Server: Msg 1038, Level 15, State 1, Line 13
Cannot use empty object or column names. Use a single space if necessary.
ASKER
Almost! Down to one error:
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '*' to a column of data type smallint.
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '*' to a column of data type smallint.
What should be the value of CrClass?
ASKER
CrClass can be a value of 1, 2, 3, or 4 or null. Is that what you needed to know?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If that works, just tell what this part should be doing?
IIf(Nz([CreditClass])=""," *",[Credit Class])
IIf(Nz([CreditClass])="","
ASKER
It works! All I can tell you is that when I run it in Access, I get another field called CCDescription that goes off the [CreditClass] so if creditclass = 1 then CCDescription = Good, if creditclass = 2 then CCDescription = Very Good, if creditclass = 3 then CCDescription = Bad, and if creditclass = 1 then CCDescription = Risk
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You're really good! Thanks for your help!
SELECT DISTINCT dbo.Balances.CurrentBalanc
dbo.Balances.Arrears2Balan
dbo.Balances.Arrears4PlusB
dbo.Customer.BillToName, dbo.Customer.BillToStreet1
dbo.Customer.BillToCity, dbo.Customer.BillToState, dbo.Customer.BillToZip,
dbo.Customer.CreditLimit, dbo.Customer.SocialSecurit
dbo.Customer.BillingGroupI
ISNULL([CreditClass], '*') AS CrClass,
dbo.SalesPersonnel.SalesGr
dbo.Customer.InvoiceRespon
FROM ((Customer RIGHT JOIN dbo.Balances ON dbo.Customer.CustID = dbo.Balances.CustID)
LEFT JOIN dbo.BillingGroup ON dbo.Customer.BillingGroupI
LEFT JOIN dbo.SalesPersonnel ON dbo.Customer.SalesID = dbo.SalesPersonnel.SalesID
WHERE (((dbo.Customer.CustomerAc