Solved

sql query error

Posted on 2009-07-01
4
305 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

777 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