POWER QUERY SQL SERVER statement error

shophoney

Active Member
Joined
Jun 16, 2014
Messages
286
Hi I need help converting a MS access sql statement. I ran it throuhg an online converter and everything has been fine. But I've been told to speed up the data selection I should put into my sql server query the date filter.

But when I try it now says the query is invalid based on the last line "Having..."

Any thoughts?

I'm connecting to our retail management system that is in Sql Server. And using Excel power query to draw the data.

Below is a copy of the statement:

SELECT tblsale.sale_link,
tblsale.loc_code AS [LOC#],
tblsale.date AS [TRANS DATE],
tblsale.time,
tblsale.trans_no AS [TRANS#],
tblsale.customer_code AS [CUST#],
tblsalecommission.salesperson,
tblsaleitem.sku_no AS [SKU#],
tblsaleitem.description,
Min(tblsalediscount.disc_code) AS [DISCOUNT CODE],
tblsaleitem.qty AS [UNITS SOLD],
Sum(tblsaleitem.ext_cost) AS COST,
[unit_ext_price] - [unit_ext_best_price] AS DISCOUNT,
tblsaleitem.unit_ext_price,
tblsaleitem.unit_ext_best_price AS [NET RETAIL],
tblsaleitem.line_no,
tblsale.trans_type,
tblsale.void_code,
tblsale.suspended,
tblsaleitem.affect_inv,
tblsaleitem.affect_total,
tblsale.note AS [SALE NOTE],
tblsaleitem.note AS [SALE ITEM NOTE]
FROM tblsalediscount
RIGHT JOIN (tblsale
INNER JOIN (tblsaleitem
INNER JOIN tblsalecommission
ON ( tblsaleitem.line_no =
tblsalecommission.line_no )
AND ( tblsaleitem.sale_link =
tblsalecommission.sale_link ))
ON tblsale.sale_link = tblsaleitem.sale_link)
ON ( tblsalediscount.line_no = tblsaleitem.line_no )
AND ( tblsalediscount.sale_link = tblsaleitem.sale_link )
GROUP BY tblsale.sale_link,
tblsale.loc_code,
tblsale.date,
tblsale.time,
tblsale.trans_no,
tblsale.customer_code,
tblsalecommission.salesperson,
tblsaleitem.sku_no,
tblsaleitem.description,
tblsaleitem.qty,
[unit_ext_price] - [unit_ext_best_price],
tblsaleitem.unit_ext_price,
tblsaleitem.unit_ext_best_price,
tblsaleitem.line_no,
tblsale.trans_type,
tblsale.void_code,
tblsale.suspended,
tblsaleitem.affect_inv,
tblsaleitem.affect_total,
tblsale.note,
tblsaleitem.note
HAVING (( ( tblsale.date ) ># 1 / 31 / 2015 # ));
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This isn't really Power bi, however ....

the syntax for a date is like this 'yyyymmdd'

i wouldn't use having either. I would write this

Where tblsale.date > '20150131'
 
Last edited:
Upvote 0
This isn't really Power bi, however ....

the syntax for a date is like this 'yyyymmdd'

i wouldn't use having either. I would write this

Where tblsale.date > '20150131'

Hi Matt. This is the error I get when I apply the suggested change in the statement.

DataSource.Error: Microsoft SQL: Incorrect syntax near the keyword 'Where'.
Details:
DataSourceKind=SQL
DataSourcePath=server;DB0001_160517195223
Message=Incorrect syntax near the keyword 'Where'.
Number=156
Class=15

I think i will take you up on using your services to review the work I have done. I'm self taught so I'm sure a MVP will have more suggestions to program it the correct way.

Let me work on getting a copy organized.

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top