SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query Analyzer Error Message


Query Analyzer Error Message

Author
Message
Stacy Newsome
Stacy Newsome
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 5

I'm trying to convert an Access database to SQL Server. I've successfully imported the tables and am now trying to use the Query Analyzer to ensure the queries will work accordingly. My SQL Server skills are at the novice level at best, so please bear with me.

Below is the SQL Code from the Access database copied into the SQL Query Analyzer along with the error messages I'm getting when I Parse the query.

TRANSFORM Count(D_INMAIN.YEAR) AS [The Value]
SELECT [CONTRACTOR INFO].[DEP CONTRACTOR HIRED], Count(D_INMAIN.YEAR) AS [Total Of YEAR]
FROM D_INMAIN LEFT JOIN [CONTRACTOR INFO] ON D_INMAIN.IN_CASENO = [CONTRACTOR INFO].IN_CASENO
GROUP BY [CONTRACTOR INFO].[DEP CONTRACTOR HIRED]
ORDER BY [CONTRACTOR INFO].[DEP CONTRACTOR HIRED]
PIVOT D_INMAIN.[I\C];

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'D_INMAIN'.
Server: Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near 'PIVOT'.

Thanks for any help you can provide.


MVDBA
MVDBA
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18071 Visits: 883
This one's simple enough- there's no TRANSFORM or PIVOT functions in SQL - these are access functions.

it is possible to make a pivot table, but you have to do this by using CASE statements

SELECT Year,
SUM(CASE Quarter WHEN 1 THEN Amount ELSE 0 END) AS Q1,
SUM(CASE Quarter WHEN 2 THEN Amount ELSE 0 END) AS Q2,
SUM(CASE Quarter WHEN 3 THEN Amount ELSE 0 END) AS Q3,
SUM(CASE Quarter WHEN 4 THEN Amount ELSE 0 END) AS Q4
FROM Northwind.dbo.Pivot
GROUP BY Year
GO

Hope this helps

MVDBA
Stacy Newsome
Stacy Newsome
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 5
Thank you very much.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search