?
Solved

sql query error

Posted on 2009-07-01
4
Medium Priority
?
309 Views
Last Modified: 2012-05-07
I am getting error for the line where i am trying to convert date.

Msg 102, Level 15, State 1, Line 3
Incorrect syntax '('.  

Do i have my syntax wrong

(MAX(CONVERT(VARCHAR(10)(p21_sales_history_view.invoice_date),101) AS [Sales Date]
SELECT     p21_sales_history_view.salesrep_id, 
                      p21_sales_history_view.salesrep_first_name + ' ' + p21_sales_history_view.salesrep_last_name AS [Sales Rep], p21_item_view.upc_code, 
                      p21_sales_history_view.cogs_amount, MAX(CONVERT(VARCHAR(10)(p21_sales_history_view.invoice_date),101) AS [Sales Date]
FROM         p21_sales_history_view INNER JOIN
                      p21_item_view ON p21_sales_history_view.item_id = p21_item_view.item_id
WHERE     (p21_sales_history_view.supplier_id IN (101127, 105144, 101942, 101427, 101324, 101351, 101637, 101615, 101120, 101315))
GROUP BY p21_sales_history_view.salesrep_id, p21_item_view.upc_code, p21_sales_history_view.cogs_amount, p21_sales_history_view.supplier_id, 
                      p21_sales_history_view.salesrep_first_name + ' ' + p21_sales_history_view.salesrep_last_name

Open in new window

0
Comment
Question by:Jiggens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:pssandhu
ID: 24756817
Try this, you are missing a comma:
SELECT     p21_sales_history_view.salesrep_id, 
                      p21_sales_history_view.salesrep_first_name + ' ' + p21_sales_history_view.salesrep_last_name AS [Sales Rep], p21_item_view.upc_code, 
                      p21_sales_history_view.cogs_amount, MAX(CONVERT(VARCHAR(10),(p21_sales_history_view.invoice_date),101) AS [Sales Date]
FROM         p21_sales_history_view INNER JOIN
                      p21_item_view ON p21_sales_history_view.item_id = p21_item_view.item_id
WHERE     (p21_sales_history_view.supplier_id IN (101127, 105144, 101942, 101427, 101324, 101351, 101637, 101615, 101120, 101315))
GROUP BY p21_sales_history_view.salesrep_id, p21_item_view.upc_code, p21_sales_history_view.cogs_amount, p21_sales_history_view.supplier_id, 
                      p21_sales_history_view.salesrep_first_name + ' ' + p21_sales_history_view.salesrep_last_name

Open in new window

0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 24756842
(MAX(CONVERT(VARCHAR(10), p21_sales_history_view.invoice_date, 101) AS [Sales Date]
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 24756848
Make that:

MAX(CONVERT(VARCHAR(10), p21_sales_history_view.invoice_date, 101)) AS [Sales Date]
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24756891
Opps.. that's right. You are missing a bracket too as mathew pointed out...
P.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question