Solved

sql query error

Posted on 2009-07-01
4
304 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
  • 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 92

Expert Comment

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

Accepted Solution

by:
Patrick Matthews earned 500 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)

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now